|
1 | 1 | --- |
2 | 2 | title: Secrets Store now available with AI Gateway: centralize storage, management, and security of your AI provider keys with Cloudflare Secrets Store |
3 | | -date: 2025-08-25T11:00:00Z |
| 3 | +date: 2025-08-26T11:00:00Z |
4 | 4 | products: |
5 | 5 | - secrets-store |
| 6 | + - ai-gateway |
6 | 7 | --- |
7 | 8 |
|
8 | 9 | import { Card, Render, Details } from "~/components" |
9 | 10 |
|
10 | | -Cloudflare Secrets Store is now integrated with AI Gateway, allowing you to store, manage, and deploy your AI provider keys in a secure and seamless configuration. |
| 11 | +Cloudflare Secrets Store is now integrated with AI Gateway, allowing you to store, manage, and deploy your AI provider keys in a secure and seamless configuration through [Bring Your Own Key](https://developers.cloudflare.com/ai-gateway/configuration/bring-your-own-keys/). Instead of passing your AI provider keys directly in every request header, you can centrally manage each key with Secrets Store and deploy in your gateway configuration using only a reference. |
11 | 12 |
|
12 | 13 | You can now create a secret directly from your AI Gateway [in the dashboard:](http://dash.cloudflare.com/?to=/:account/ai-gateway) by navigating into your gateway -> **Provider Keys** -> **Add**. |
13 | 14 |
|
14 | 15 |  |
15 | 16 |
|
16 | | -You can create your secret with the newly available **ai_gateway** scope via [wrangler](https://developers.cloudflare.com/workers/wrangler/commands/), the [Secrets Store dashboard](http://dash.cloudflare.com/?to=/:account/secrets-store), or the [API](https://developers.cloudflare.com/api/resources/secrets_store/): |
| 17 | +You can also create your secret with the newly available **ai_gateway** scope via [wrangler](https://developers.cloudflare.com/workers/wrangler/commands/), the [Secrets Store dashboard](http://dash.cloudflare.com/?to=/:account/secrets-store), or the [API](https://developers.cloudflare.com/api/resources/secrets_store/): |
| 18 | + |
| 19 | +Once you have created your secret with an **AI Gateway** scope, pass the key in the request header using its Secrets Store reference: |
17 | 20 |
|
18 | 21 | ``` |
19 | | -curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/secrets_store/stores/$STORE_ID/secrets" \ |
20 | | - --request POST \ |
21 | | - --header "X-Auth-Email: $CLOUDFLARE_EMAIL" \ |
22 | | - --header "X-Auth-Key: $CLOUDFLARE_API_KEY" \ |
23 | | - --json '[ |
24 | | - { |
25 | | - "name": "<MY_SECRET_NAME>", |
26 | | - "value": "<SECRET_VALUE>", |
27 | | - "scopes": [ |
28 | | - "workers" |
29 | | - ], |
30 | | - "comment": "" |
31 | | - }, |
32 | | - { |
33 | | - "name": "<MY_SECRET_NAME_2>", |
34 | | - "value": "<SECRET_VALUE>", |
35 | | - "scopes": [ |
36 | | - "ai_gateway" |
37 | | - ], |
38 | | - "comment": "" |
39 | | - } |
40 | | - ]' |
41 | | -``` |
| 22 | +curl -X POST https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/my-gateway/anthropic/v1/messages \ |
| 23 | + --header 'cf-aig-authorization: CLOUDFLARE_AI_GATEWAY_TOKEN \ |
| 24 | + --header 'anthropic-version: 2023-06-01' \ |
| 25 | + --header 'Content-Type: application/json' \ |
| 26 | + --data '{"model": "claude-3-opus-20240229", "messages": [{"role": "user", "content": "What is Cloudflare?"}]}' |
| 27 | + ``` |
| 28 | + |
| 29 | + Or, using Javascript: |
| 30 | + |
| 31 | + ``` |
| 32 | + import Anthropic from '@anthropic-ai/sdk'; |
| 33 | +
|
| 34 | +
|
| 35 | +const anthropic = new Anthropic({ |
| 36 | + apiKey: "CLOUDFLARE_AI_GATEWAY_TOKEN", |
| 37 | + baseURL: "https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/my-gateway/anthropic", |
| 38 | +}); |
| 39 | +
|
| 40 | +
|
| 41 | +const message = await anthropic.messages.create({ |
| 42 | + model: 'claude-3-opus-20240229', |
| 43 | + messages: [{role: "user", content: "What is Cloudflare?"}], |
| 44 | + max_tokens: 1024 |
| 45 | +}); |
| 46 | +``` |
| 47 | + |
| 48 | +For more information, check out the [blog](https://blog.cloudflare.com/ai-gateway-aug-2025-refresh)! |
0 commit comments