Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/content/docs/ai-gateway/configuration/caching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Enable and customize your gateway cache to serve requests directly from Cloudfla

:::note

Currently caching is supported only for text and image responses, and it applies only to identical requests.
Currently caching is supported only for text and image responses, and it applies only to identical requests.

This is helpful for use cases when there are limited prompt options - for example, a support bot that asks "How can I help you?" and lets the user select an answer from a limited set of options works well with the current caching configuration.
We plan on adding semantic search for caching in the future to improve cache hit rates.
Expand Down Expand Up @@ -73,7 +73,7 @@ As an example, when submitting a request to OpenAI, include the header in the fo

```bash title="Request skipping the cache"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer $TOKEN' \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--header 'cf-aig-skip-cache: true' \
--data ' {
Expand All @@ -98,7 +98,7 @@ As an example, when submitting a request to OpenAI, include the header in the fo

```bash title="Request to be cached for an hour"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer $TOKEN' \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--header 'cf-aig-cache-ttl: 3600' \
--data ' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In this example, if you have a negotiated price of $1 per million input tokens a

```bash title="Request with custom cost"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer $TOKEN' \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--header 'cf-aig-custom-cost: {"per_token_in":0.000001,"per_token_out":0.000002}' \
--data ' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In the example below, we use `cf-aig-collect-log` to bypass the default setting

```bash
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer $TOKEN' \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--header 'cf-aig-collect-log: false \
--data ' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ pcx_content_type: reference
title: Zone Analytics Colos Endpoint to GraphQL Analytics
sidebar:
order: 13

---

import { Details } from "~/components"
import { Details } from "~/components";

This guide shows how you might migrate from the deprecated (and soon to be sunset) zone analytics API to the GraphQL API. It provides an example for a plausible use-case of the colos endpoint, then shows how that use-case is translated to the GraphQL API. It also explores features of the GraphQL API that make it more powerful than the API it replaces.

Expand All @@ -18,8 +17,8 @@ curl -H "Authorization: Bearer $API_TOKEN" "https://api.cloudflare.com/client/v4

This query says:

* Given an `API_TOKEN` which has Analytics Read access to `ZONE_ID`.
* Fetch colos analytics for `ZONE_ID` with a time range that starts on
- Given an `API_TOKEN` which has Analytics Read access to `ZONE_ID`.
- Fetch colos analytics for `ZONE_ID` with a time range that starts on
`2020-12-10T00:00:00Z` (`since` parameter) to now.

The question that we want to answer is: "What is the number of requests for ZHR per hour?" Using the colos endpoint response data and some wrangling by jq we can answer that question with this command:
Expand Down Expand Up @@ -57,7 +56,6 @@ This selects only lines that contain more than 0 requests and the `colo_id` is Z

The final data we get looks like the following response:


<Details header="Response">

```json
Expand All @@ -75,7 +73,6 @@ The final data we get looks like the following response:
...
```


</Details>

How do we get the same result using the GraphQL API?
Expand Down Expand Up @@ -112,7 +109,7 @@ The following is a GraphQL API query to retrieve the data we need to answer the
Then we can run it with curl:

```bash
curl -X POST -H 'Authorization: Bearer $API_TOKEN' https://api.cloudflare.com/client/v4/graphql -d "@./coloGroups.json" > graphqlColoGroupsResponse.json
curl -X POST -H "Authorization: Bearer $API_TOKEN" https://api.cloudflare.com/client/v4/graphql -d "@./coloGroups.json" > graphqlColoGroupsResponse.json
```

We can answer our question in the same way as before using jq:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Send a `PUT` request to the [Update Zero Trust account configuration](/api/resou

```sh
curl --request PUT \
'https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/configuration' \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/configuration" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
Expand Down