Use the Anthropic SDK
Send Claude requests through CoreValue with Anthropic's own SDK: change the base URL and the key, and keep using the Messages API.
CoreValue's gateway accepts Anthropic's native Messages API. Point the Anthropic SDK at it and use your CoreValue key in place of your Anthropic key. Requests are forwarded in Anthropic's own format, so tool use, extended thinking, prompt caching and streaming are passed through unchanged.
Before you start: add your Anthropic key under Gateway → Provider keys and create a CoreValue key under Governance → Keys. The Quickstart walks through both.
Change two lines
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://gateway.corevalue.dev",
api_key=os.environ["COVA_API_KEY"], # sk-cova-…
)
message = client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://gateway.corevalue.dev",
apiKey: process.env.COVA_API_KEY, // sk-cova-…
});
const message = await client.messages.create({
model: "claude-sonnet-4-5-20250929",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
console.log(message.content[0].type === "text" ? message.content[0].text : "");Both SDKs read these when you construct the client with no arguments:
ANTHROPIC_BASE_URL=https://gateway.corevalue.dev
ANTHROPIC_API_KEY=sk-cova-…The base URL has no /v1: the SDK adds /v1/messages itself.
Pass the CoreValue key as the API key, not as an auth token. The gateway
reads it from the x-api-key header, which is where the SDK sends api_key.
auth_token (and the ANTHROPIC_AUTH_TOKEN variable) sends it as a bearer
token instead, and the request is refused.
Tag requests with who and what they are for
client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
extra_headers={
"Cova-Customer-Id": "acme-corp",
"Cova-Feature-Id": "support-bot",
},
)await client.messages.create(
{
model: "claude-sonnet-4-5-20250929",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
},
{ headers: { "Cova-Customer-Id": "acme-corp", "Cova-Feature-Id": "support-bot" } },
);Set them once on the client with default_headers (Python) or
defaultHeaders (TypeScript) if every request from a service shares them. See
Tag your traffic and the full list in
Headers.
Read the cost of a request
Non-streaming responses carry Cova-Request-Cost in US dollars:
raw = client.messages.with_raw_response.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(raw.headers.get("Cova-Request-Cost"))
message = raw.parse()const { data, response } = await client.messages
.create({
model: "claude-sonnet-4-5-20250929",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
})
.withResponse();
console.log(response.headers.get("Cova-Request-Cost"));For a streamed request, the cost arrives after the stream ends. See Request cost lookup and How cost is calculated.
When a budget runs out
If a budget is set to block, the gateway refuses the request with HTTP 429
before it reaches Anthropic, and the SDK raises its usual rate-limit error. The
Anthropic SDK retries a 429 by default, so a refused request may be tried
again a few times before the error reaches your code. See
Errors and Budgets and limits.
Using Claude Code
Claude Code reads the same two variables. See Claude Code.
Use the OpenAI SDK
Send requests through CoreValue with the OpenAI SDK you already use: change the base URL and the key, and keep your code.
Use the Google Gemini SDK
Use Google's official @google/genai SDK with Cova AI Gateway: your app sends only its Cova key, and the gateway uses the Google key stored in CoreValue.