Skip to content
SayGMDocs
Dashboard

Anthropic compatibility

Set the Anthropic client’s base URL to https://api.saygm.com. The SDK adds /v1/messages and sends the SayGM key through the native x-api-key header.

The gateway reads the model, output limit, and inline-image information to route the request and check available credit. It forwards the Messages body, with parameter adjustments listed below. Supported means the gateway accepts or forwards the feature; the selected provider validates the request. Check the current model catalog for model-specific capabilities.

Feature Status Behavior
Non-streaming Messages Supported Omit stream or set it to false to use the non-streaming pipeline.
Streaming Messages Supported Set stream to true to receive the Messages event stream.
System prompt Supported Top-level system is forwarded, and so is a role: "system" message. Providers differ on the message form; the top-level block works everywhere.
Multi-turn messages Supported The request’s messages array, including prior turns, is forwarded to the selected route.
Tool use and tool_result continuation Supported Tool and result blocks are forwarded in the Messages body.
Image input Partial Base64 images are counted in the admission estimate and forwarded. URL images are forwarded for the provider to fetch and sit outside the estimate.
Prompt caching, 5-minute and 1-hour TTLs Supported Cache controls and anthropic-beta pass through. Cache reads and both cache-write tiers are settled at their own rates.
Extended or adaptive thinking and effort Supported thinking and output_config.effort pass through unchanged. Which values a model accepts is the model’s own rule.
stop_sequences Supported The field passes through in the Messages body.
metadata.user_id Supported The field passes through in the body; GM account attribution uses the API key.
max_tokens Supported Forwarded as sent. When your balance covers less than you asked for, the gateway lowers it to fit before dispatch.
temperature, top_p, and top_k Partial A route drops the controls its provider rejects and names them in the x-gm-params-dropped response header.
Endpoint Status Response
POST /v1/messages Supported stream: false or an omitted stream selects a JSON response; stream: true selects streaming.
POST /v1/messages/count_tokens Unsupported Returns HTTP 404 in the Anthropic error envelope with error.type: "not_found_error". The smoke sequence shows the exact response.
Messages Batches paths, including /v1/messages/batches and its subpaths Unsupported Return HTTP 404 in the Anthropic envelope with error.type: "not_found_error"; the message identifies the unknown method and path.
Other unknown paths under /v1/messages Unsupported Return HTTP 404 in the same Anthropic envelope with error.type: "not_found_error"; the message identifies the unknown method and path.
Anthropic Files paths under /v1/files Unsupported Return HTTP 404 with error.type: "invalid_request_error", error.code: "unknown_endpoint", error.param: null, and error.request_id. The message is Unknown endpoint: <METHOD> <PATH>. in the OpenAI-style envelope.
Legacy Text Completions POST /v1/complete Unsupported Return HTTP 404 through the same generic fallback as Files, with message Unknown endpoint: POST /v1/complete..
Direction Header Behavior
Request x-api-key Required; authenticates the buyer’s GM account.
Request anthropic-version Required and forwarded to the selected route.
Request anthropic-beta Optional and forwarded; repeated values are passed through.
Request X-GM-Routing, X-GM-Providers, X-GM-Model-Cascade Read by the gateway for per-request routing; X-GM-Providers applies to single-model requests and is rejected with multi-model cascades. See routing.
Response x-gm-request-id, request-id Both contain the same gateway-generated request ID on Messages success and error responses.
Response x-gm-model-served On a successful inference response, identifies the catalog product served as provider:model.
Response x-gm-params-dropped Lists removed parameter names, separated by commas, from the successful attempt. Present when parameter translation drops a field.

Set model to an exact id returned by GET /v1/models?api_shape=messages. The gateway resolves that exact catalog ID.

import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.saygm.com",
api_key=os.environ["GM_API_KEY"],
)
message = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello."}],
)
print(message.content[0].text)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.saygm.com",
apiKey: process.env.GM_API_KEY,
});
const message = await client.messages.create({
model: "claude-opus-4-8",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hello." }],
});
console.log(message.content[0].text);

Discover compatible models with:

Terminal window
curl -fsSL "https://api.saygm.com/v1/models?api_shape=messages"

Replace the placeholder with a SayGM key that has credit. The examples use claude-haiku-5-5; any id from the Messages catalog works.

Terminal window
export GM_API_KEY="gm_live_…"

Non-streaming request: on success, expect HTTP 200 and a Messages JSON body. The x-gm-request-id and request-id response headers have the same value.

Terminal window
curl -i "https://api.saygm.com/v1/messages" \
-H "x-api-key: $GM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-haiku-5-5",
"max_tokens": 32,
"messages": [{"role": "user", "content": "Reply with OK."}]
}'

Streaming request: on success, expect HTTP 200 and Messages events, ending with message_stop.

Terminal window
curl -i -N "https://api.saygm.com/v1/messages" \
-H "x-api-key: $GM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-haiku-5-5",
"max_tokens": 32,
"stream": true,
"messages": [{"role": "user", "content": "Reply with OK."}]
}'

Cache-control request: the loop sends the same body twice. This short prefix checks the request shape. Inspect usage.cache_creation_input_tokens and usage.cache_read_input_tokens; either can be zero. Cache reuse depends on the provider’s minimum prefix length, retention rules, and route reuse. To exercise a cache write and read, use a fixed prefix that meets the selected model’s caching requirements.

Terminal window
GM_CACHE_BODY='{
"model": "claude-haiku-5-5",
"max_tokens": 32,
"system": [{
"type": "text",
"text": "A fixed preamble for this cache smoke test.",
"cache_control": {"type": "ephemeral"}
}],
"messages": [{"role": "user", "content": "Reply with OK."}]
}'
for attempt in 1 2; do
curl -i "https://api.saygm.com/v1/messages" \
-H "x-api-key: $GM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d "$GM_CACHE_BODY"
done

Count-token preflight: expect HTTP 404 and this envelope, with the gateway’s request ID in place of the placeholder:

{
"type": "error",
"error": {
"type": "not_found_error",
"message": "Token counting is not available on this gateway. You can send the request without a preflight count."
},
"request_id": "<gateway-request-id>"
}
Terminal window
curl -i "https://api.saygm.com/v1/messages/count_tokens" \
-H "x-api-key: $GM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-haiku-5-5",
"messages": [{"role": "user", "content": "Reply with OK."}]
}'

Every response with billable usage carries the amount it is charged inside usage, alongside the normal token counts:

{
"usage": {
"input_tokens": 12,
"output_tokens": 9,
"cost": 0.000140000,
"cost_nano_usd": 140000
}
}

cost is USD, rendered as a JSON number with exactly nine fractional digits. cost_nano_usd is the same amount as an integer in nano-USD (1 nUSD = 10⁻⁹ USD), the unit used by GET /v1/credits. See per-request cost for what the figure includes and when it reaches the balance.

The Anthropic SDKs keep these extra fields, so message.usage.cost works in Python. When streaming, they arrive on the final message_delta event. See streaming disconnects for what is charged when you disconnect early.