Client guide
Your SDK. Your accounts.
Heimdall speaks the OpenAI, Anthropic and Google Gemini APIs. Keep your SDK and your code. Change the base URL and the key, and your calls run on the Claude, ChatGPT and Google accounts you connected in the portal. Model ids are the real vendor ids, so going to production later is the same change in reverse.
Examples use http://localhost:8000, the API address on a default install (the installer prints it). Use your own address if you changed it. Keys start with cgw_; create them in the portal under API keys. Keep keys on your server, never in a browser or mobile app.
Connect your SDK
OpenAI SDK (base URL ends in /v1):
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="cgw_...")
r = client.chat.completions.create(model="gpt-5.6-luna", messages=[{"role": "user", "content": "Say hi"}])
print(r.choices[0].message.content)
Anthropic SDK (base URL without /v1):
from anthropic import Anthropic
client = Anthropic(base_url="http://localhost:8000", api_key="cgw_...")
r = client.messages.create(model="claude-sonnet-5-5", max_tokens=300, messages=[{"role": "user", "content": "Say hi"}])
print(r.content[0].text)
Google GenAI SDK:
from google import genai
client = genai.Client(api_key="cgw_...", http_options={"base_url": "http://localhost:8000"})
r = client.models.generate_content(model="gemini-3-flash", contents="Say hi")
print(r.text)
JavaScript is the same change: new OpenAI({ baseURL: "http://localhost:8000/v1", apiKey }) and new Anthropic({ baseURL: "http://localhost:8000", apiKey }). LangChain: ChatOpenAI(base_url=".../v1") and ChatAnthropic(base_url="..."). Vercel AI SDK: createOpenAI and createAnthropic both take baseURL: ".../v1".
Any model works through any of the three SDKs: claude-sonnet-5-5 through the OpenAI SDK, gemini-3-flash through the Anthropic SDK, and so on. Send model: "auto" to let Heimdall pick. Heimdall accepts the key the way each SDK sends it: Authorization: Bearer, X-API-Key (also the Anthropic SDK's x-api-key), x-goog-api-key or ?key=.
Point base_url back at the vendor and use your paid API key. Model ids stay the same. Only auto and models from another vendor (for example a Claude model through the OpenAI SDK) need changing.
What works
A test script runs every client below against all three providers for plain, streaming, tool and JSON-schema calls, and writes the result to docs/product/parity.md. A pass also requires that the provider under test answered (no silent failover). The tables below are copied from that file; if they differ, the file wins.
Generated by tests/sdk/run.py on 2026-10-14 17:30 UTC (run c3cecd0a). Models: claude haiku, codex gpt-5.6-luna, agy gemini-3-flash.
| Client | claude plain | claude stream | claude tools | claude json | codex plain | codex stream | codex tools | codex json | agy plain | agy stream | agy tools | agy json |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| openai-py | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| anthropic-py | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| google-genai-py | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| langchain-openai | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| langchain-anthropic | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| openai-js | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| anthropic-js | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| vercel-ai-openai | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| vercel-ai-anthropic | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ retry | ✅ | ✅ | ✅ | ✅ |
| Surface | Feature | Status | Note |
|---|---|---|---|
| OpenAI chat | n > 1 | unsupported | HTTP 400 |
| OpenAI chat | logprobs | unsupported | accepted, not returned |
| OpenAI chat | json_object mode | best-effort | prompt-guided; returned valid JSON |
| OpenAI responses | previous_response_id | unsupported | stateless: send the whole conversation |
| OpenAI responses | built-in tools (web_search…) | unsupported | HTTP 400 |
| OpenAI embeddings | dimensions other than 1024 | unsupported | self-hosted multilingual-e5-large, 1024-d; ≤64 inputs per call |
| Anthropic | /v1/messages/count_tokens | unsupported | HTTP 404 |
| Anthropic | server tools (web_search…) | unsupported | HTTP 400 |
| Gemini | countTokens | unsupported | HTTP 404 |
| API | Endpoints |
|---|---|
| OpenAI | POST /v1/chat/completions · POST /v1/responses · GET /v1/models · POST /v1/embeddings · POST /v1/images/generations · POST /v1/images/edits |
| Anthropic | POST /v1/messages · GET /v1/models |
| Gemini | POST /v1beta/models/{model}:generateContent · :streamGenerateContent?alt=sse · GET /v1beta/models |
Unknown endpoints (batches, files, moderations, ...) return a 404 in that vendor's error shape.
Images. /v1/images/generations and /v1/images/edits make images on your accounts. The default is Google's gemini-3.1-flash-image (fast, JPEG). Send quality: "high" or a gpt-image-* model for ChatGPT images (PNG, about 30 s). Edits take one or more reference images, no masks. Only b64_json output. A free Google account makes about 13 images per 5 hours; when every account is at its limit you get 429 image_quota_exhausted.
/v1/embeddings needs the optional embeddings add-on (see INSTALL.md). Whatever model you name, you get the self-hosted multilingual-e5-large: 1024 numbers per vector, not OpenAI's 1536. Build a new 1024-dimension index and re-embed your documents. dimensions must be 1024 or left out. At most 64 inputs per call (in LangChain set chunk_size to 64 or less). Send "input_type": "query" (in extra_body) for search queries; the default is "passage".
Models
GET /v1/models lists the models your connected accounts can serve now, in the asking SDK's shape. Heimdall re-checks each vendor's model list once a day and tests new models with one tiny call before listing them. Today's list on this install (last checked 2026-11-27 21:00 UTC):
| Provider | Effort field | Models |
|---|---|---|
claude | yes | claude-haiku-4-5 · claude-haiku-4-5-20251001 · claude-haiku-5-5 · claude-opus-4-5-20251101 · claude-opus-4-6 · claude-opus-4-7 · claude-opus-4-8 · claude-opus-5 · claude-opus-5-5 · claude-sonnet-4-6 · claude-sonnet-5 · claude-sonnet-5-5 · haiku · opus · sonnet |
codex | yes | gpt-5.6-luna · gpt-5.6-sol · gpt-5.6-terra · gpt-6-astra · gpt-6-luna · gpt-6-sol · gpt-6.1-sol · gpt-6.1-terra · gpt-6.2-astra · gpt-6.2-sol |
agy | baked in | claude-opus-4-6-thinking · claude-sonnet-4-6 · gemini-2.5-flash · gemini-2.5-flash-lite · gemini-2.5-flash-thinking · gemini-3-flash · gemini-3.1-flash-image · gemini-3.1-flash-lite · gemini-3.5-flash-lite · gemini-3.8-flash-high · gemini-3.8-flash-low · gemini-3.8-flash-medium · gemini-3.8-flash-tiered · gemini-4-hydrogen-sonar · gpt-oss-120b-medium |
claudeis your Claude account,codexyour ChatGPT account,agyyour Google (Antigravity) account.auto: Heimdall sizes the request and picks a model. Fine for trying things; pin a real id before production.- Claude aliases
sonnet,opus,haikuresolve to the latest model of each family. - Google models have no effort setting; the effort is in the name (
gemini-3.8-flash-low/-medium/-high). - A model no longer in the list returns 404 model_not_found.
Each project has a Caller picks the model switch (portal, Projects). It is on for projects you create on your own install. Turn it off and every call routes automatically: a Claude model you name is ignored, and naming a ChatGPT or Google model returns 403 provider_not_permitted.
What the response tells you
Non-streaming answers carry an extra heimdall field: provider, model, api_equivalent_usd (what the call would have cost on the vendor's paid API) and job_id. Every answer has a request-id and x-request-id header; quote it when you report a problem.
Failover is never silent. If an account or provider failed or was at its limit and another one answered, the response says so:
- header
X-Heimdall-Failover: claude=invalid_output, codex=codex_cooling(every surface, streaming too); - and, where the body has a
heimdallfield,heimdall.failover = [{from, account, code, reason, resets_at, transport}](accountis set when one of several accounts of the same provider was skipped).
heimdall.provider and heimdall.model name what actually answered.
Heimdall extras in the request
transport(body field;extra_bodyin the SDKs): how the call reaches the vendor. See How calls run.X-User-IDheader: a stable id for one of your own end users. Usage is broken down per user; leave it out and the call counts for the project as a whole.
Caching
SDK calls run fresh, as they would against the vendor. To reuse an identical answer, send Cache-Control: max-age=<seconds> (capped at 30 days). Add no-cache to run fresh and store the new answer; no-store skips the cache.
Advanced API
Quickstart: /v1/run
The SDK endpoints above are the main way in. The endpoints below are Heimdall's own API: a multipart /v1/run with files, JSON-schema output on any model, response caching on by default, async jobs and webhooks. Requests are multipart/form-data (use -F in curl), so files and text use one code path.
curl http://localhost:8000/v1/run \
-H "X-API-Key: $HEIMDALL_KEY" \
-F 'prompt=Summarize the theory of relativity in one sentence.'
output is the answer. meta says which provider, model and effort produced it (effort is null for Google models), how it was routed, and the token counts:
{
"status": "completed",
"output": "Relativity holds that space and time form a single fabric…",
"meta": {
"provider": "codex",
"model": "gpt-5.6-terra",
"effort": "medium",
"routed_by": "classifier",
"input_tokens": 28,
"output_tokens": 41
}
}
Routing & failover
With provider=auto (the default), a small classifier model rates the request trivial, standard or hard and routes it to a model that fits. If that account is at its limit, the call moves to the next account, then the next provider, in the order set in the portal. The answer's meta and the failover header say where it went.
Effort
The effort field (low, medium, high; default medium) sets how hard reasoning models think. It applies to Claude and ChatGPT models; Google models ignore it.
Fast
Classification, extraction, short rewrites: mini/flash-class models.
Balanced
Most everyday generation and reasoning.
Deep
Long context, multi-step reasoning: the strongest tier.
How calls run
Heimdall reaches each provider in one of two ways, with the same signed-in accounts:
- Direct: Heimdall calls the vendor's API itself. Fast; supports streaming, tool calls and images.
- CLI: Heimdall runs the vendor's command-line tool (
claude,codex). Slower and returns the final text only.
By default calls run hybrid: direct first, and the CLI only if the vendor changed its API in a way Heimdall doesn't handle yet. Choose per call with transport:
transport | What happens |
|---|---|
hybrid (default) | Direct, falling back to the CLI when the direct call can't be made. |
direct | Direct only. A vendor change shows up as an error instead of a slower answer. |
cli | Every call runs through the vendor's CLI. A request with tools is refused on cli. |
passthrough | Sends the call to the vendor's paid API with your own API key, billed by the vendor: a last check before production. Needs GATEWAY_CLAUDE_API_KEY or GATEWAY_CODEX_API_KEY set on the gateway; otherwise 400 passthrough_not_configured. Claude and OpenAI models only. |
# /v1/run and /v1/run-async: a form field
curl http://localhost:8000/v1/run -H "X-API-Key: $HEIMDALL_KEY" \
-F 'prompt=Summarize this.' -F 'transport=cli'
# the SDKs: a body field, via extra_body
client.chat.completions.create(model="auto", messages=[...], extra_body={"transport": "cli"})
On /v1/run, meta.transport says which path ran (direct or cli) and meta.transport_fallback explains a hybrid fallback. An unknown value returns invalid_transport (422 on /v1/run, 400 on the SDK endpoints).
Structured output
Pass a JSON Schema in schema and output comes back as the parsed object. Provider quirks ($ref inlining, array-root envelopes, prose-wrapped JSON) are handled for you.
curl http://localhost:8000/v1/run \
-H "X-API-Key: $HEIMDALL_KEY" \
-F 'prompt=Extract the person and their role: "Ada Lovelace, mathematician."' \
-F 'schema={"type":"object","properties":{"name":{"type":"string"},"role":{"type":"string"}},"required":["name","role"]}'
{ "status": "completed",
"output": { "name": "Ada Lovelace", "role": "mathematician" } }
If the schema's root is an array, the result comes back as {"value": [ … ]}: providers reject bare-array roots.
Model selection on /v1/run
| You send | Project without Caller picks the model | Project with it |
|---|---|---|
provider=auto (default) | Classifier and failover choose. | |
provider=codex / agy + model | 403 provider_not_permitted | Runs on that model |
provider=claude + a model | Falls back to auto-routing | Runs on that model |
provider=codex / agy without model | 422 invalid_model | |
Run a prompt
Synchronous by default; mode=async queues the job and you poll it.
Request fields
| Field | Type | Notes | |
|---|---|---|---|
prompt | string | one of | The instruction. Send exactly one of prompt or pipeline_slug. |
schema | string (JSON) | optional | JSON Schema for structured output. Invalid JSON → 422 invalid_schema. |
provider | string | optional | auto (default), claude, codex (ChatGPT), agy (Google). |
model | string | optional | Pin a model; see Models. |
effort | string | optional | low · medium (default) · high. |
transport | string | optional | hybrid (default) · direct · cli · passthrough. See How calls run. |
files | file[] | optional | Attachments, up to 20 MiB in total; more → 413 too_large. Images (png/jpg/jpeg/gif/webp) are seen by all three providers. |
mode | string | optional | sync (default) or async. |
cacheable | bool | optional | Identical requests without files are cached by default. Send false to force a fresh run. |
cache_ttl_seconds | int | optional | Cache lifetime, default 24 h, capped at 30 days. Ignored with a schema: those cache for 30 days. |
Responses
- 200
sync:{ "status": "completed", "output", "meta" } - 202
async:{ "job_id", "status": "queued" }; pollGET /v1/jobs/{job_id}
A "warning": "approaching token budget" field appears when the project nears its budget; the request still runs.
Run with a callback
For callers behind a short HTTP timeout (serverless functions). Returns 202 at once and POSTs the result to your callback_url when the job ends, on success and on failure.
Request fields
| Field | Type | Notes | |
|---|---|---|---|
prompt | string | required | Empty → 422 invalid_request. |
callback_url | string | optional | Where the result is POSTed. Leave it out and no callback fires. |
job_id | string | optional | Your own reference, echoed in the response and the callback. |
token | string | optional | Echoed in the callback body; check it to confirm the callback is genuine. |
provider · model · effort · schema · transport | — | optional | As on /v1/run. |
curl http://localhost:8000/v1/run-async \
-H "X-API-Key: $HEIMDALL_KEY" \
-F 'prompt=Draft a product changelog from these commits…' \
-F 'job_id=changelog-4821' \
-F 'token=whsec_9c2f…' \
-F 'callback_url=https://your-app.com/hooks/heimdall'
{ "accepted": true, "job_id": "changelog-4821", "gateway_job_id": "a1b2c3d4" }
The callback we send you
Up to 3 attempts while your endpoint answers non-2xx:
{
"job_id": "changelog-4821", // your job_id, echoed
"token": "whsec_9c2f…", // your token, echoed: check it
"status": "done", // "done" or "failed"
"output": "…", // null on failure
"meta": { "provider": "claude", "model": "sonnet", "effort": "medium", "routed_by": "classifier" },
"error": null // the message when status is "failed"
}
Check the echoed token before you trust a callback. Return any 2xx to acknowledge.
Embeddings
Needs the embeddings add-on. 1024-dimension vectors from multilingual-e5-large, computed on your machine. Use type: "query" for search queries and type: "passage" (default) for documents. Vectors are not unit-normalized: compare them with cosine similarity.
curl http://localhost:8000/v1/embed \
-H "X-API-Key: $HEIMDALL_KEY" \
-H "Content-Type: application/json" \
-d '{"texts": ["first document", "second document"], "type": "passage"}'
{ "model": "intfloat/multilingual-e5-large", "dim": 1024,
"vectors": [ [0.013, -0.047, …], [0.008, 0.052, …] ] }
texts takes a string or an array, at most 8 per request (more → 413 batch_too_large).
It runs on the CPU: about 1.1 s per ~350-token passage, 0.1–0.2 s for a short query. Texts are cut at 512 tokens. Requests run one at a time. Set your client timeout to at least 60 s (the gateway's own limit). For a large document, send batches of 8 one after another. A timeout or a stopped add-on returns 502 embed_unavailable; retry with backoff.
Jobs
Async runs (and mode=async) make a job you can poll, list or cancel.
Status, and once completed, output and meta. A failed job carries an error.
{
"job_id": "a1b2c3d4",
"status": "completed", // queued · running · completed · failed
"created_at": "2026-08-09T04:12:07Z",
"provider": "codex",
"requested_model": null,
"routed_model": "gpt-5.6-terra",
"routed_by": "classifier", // caller · classifier · pipeline · default
"output": "…", "meta": { … }
}
Cancels a running job. Safe to repeat; a finished job returns cancelled: false with a reason.
Your recent jobs as { job_id, status, created_at }. Filter with ?status= and ?user_id=.
Usage & health
The project's last 30 days: request counts and token totals by provider.
200 when the gateway is healthy, 503 otherwise. The body has providers (per provider enabled / ok), accounts (sign-in state per Claude and ChatGPT account) and embed (the embeddings add-on).
embed.ok is false when the add-on is off, loading, or slow (p95 over 3 s per text, last ping over 2 s, or a timeout in the last 10 minutes; embed.reason says which). It does not change the top-level ok.
Errors
Heimdall's own endpoints (/v1/run, /v1/run-async, /v1/embed, jobs) answer { "status": "failed", "error": { "code", "message" } }. The OpenAI, Anthropic and Gemini endpoints answer in that vendor's error shape, so your SDK raises its usual exception, with the same codes inside.
| Status | Code | Meaning |
|---|---|---|
| 401 | unauthorized | Missing or unknown key. |
| 403 | provider_not_permitted | Named a ChatGPT or Google model in a project without Caller picks the model. |
| 422 | invalid_model | (/v1/run) Model missing for codex/agy, or not in the current list. |
| 422 | invalid_schema · invalid_provider · invalid_effort | A field failed validation. |
| 422 / 400 | invalid_transport | Unknown transport (422 on /v1/run, 400 on the SDK endpoints). |
| 400 | passthrough_not_configured | transport=passthrough without that vendor's API key on the gateway. |
| 400 | invalid_request · unsupported_content | (SDK endpoints) A field the endpoint doesn't support, e.g. n > 1, built-in/server tools, audio or document parts. |
| 404 | model_not_found | (SDK endpoints) The model isn't in the current list. |
| 413 | too_large · batch_too_large | Upload over 20 MiB, or too many texts in one embeddings request. |
| 429 | image_quota_exhausted | Every image account is at its limit until its reset. |
| 429 | budget_exceeded | The project hit its budget. |
| 429 | all_subscription_seats_busy · all_providers_cooling | Every account that could answer is busy or at its limit. Retry with backoff. |
| 502 | {provider}_failed | The call failed on every account and provider it tried. |
| 502 | embed_unavailable | The embeddings add-on is off, unreachable or timed out. |
| 504 | *_timeout | The vendor timed out. |
429 and 5xx can succeed on retry; use exponential backoff. 401, 403, 404, 413 and 422 won't; fix the request.
Model changes
- 2026-10-15: Google's Gemini models are
gemini-3.8-flash-low/-medium/-high. The oldergemini-3.6-flash-*andgemini-3.1-pro-*ids were retired by Google. - 2026-10-14: the paid
geminiprovider is gone;provider=geminireturns 422 invalid_provider. Gemini models run on Google accounts (provider=agy). - ChatGPT's
gpt-6models are never picked byauto; name one to use it. By defaultautousesgpt-5.6-luna,gpt-5.6-terraandgpt-5.6-solfor trivial, standard and hard work.