-
Notifications
You must be signed in to change notification settings - Fork 252
Open
Description
With the following set up:
- Authenticated Cloudflare AI Gateway
- Anthropic API token stored in AI Gateway's Provider Key
- @ai-sdk/anthropic
To successfully set up @ai-sdk/anthropic
, you need to specify
const anthropic = createAnthropic({
apiKey: "",
baseURL: await env.AI.gateway(env.GATEWAY_ID).getUrl("anthropic"),
headers: {
"cf-aig-authorization": `Bearer ${env.GATEWAY_API_KEY}`,
}
});
apiKey
is needed even if it's an empty string even though we've provided the Anthropic api key to AI Gateway. ai-sdk will throw an exception if it's not defined (andANTHROPIC_API_KEY
doesn't exist in env)- passing in custom header for
cf-aig-authorization
is needed if running authenticated AI Gateway
It would be ideal if AI Gateway will take the gateway API key as apiKey and move it to x-api-token
so that the definition could just be
const anthropic = createAnthropic({
apiKey: GATEWAY_API_KEY,
baseURL: await env.AI.gateway(env.GATEWAY_ID).getUrl("anthropic")
});
Metadata
Metadata
Assignees
Labels
No labels