Sending requests
Call any model through the gateway in the OpenAI or Anthropic format, for a customer and a member.
The gateway speaks three wire formats, so you keep the SDK you already use and change its base URL and key. Every request can name the customer and the member it is for; the gateway checks their limits and balance, calls the provider, streams the answer back unchanged and records the usage.
Endpoints#
| Format | Method and path | Base URL for the official SDK |
|---|---|---|
| OpenAI Responses | POST /v1/responses | https://api.hixel.dev/v1 |
| OpenAI Chat Completions | POST /v1/chat/completions | https://api.hixel.dev/v1 |
| Anthropic Messages | POST /v1/messages | https://api.hixel.dev |
Any format can call any model in the environment's catalog. When the format you send differs
from the provider's own (Chat Completions to a Claude model, Messages to a GPT model), the
gateway translates the request and the response, streams included. A parameter the provider
has no way to express is refused with unsupported_parameter and the field in param.
Beside chat, the gateway also serves /v1/embeddings, /v1/images/generations,
/v1/images/edits, /v1/audio/speech, /v1/audio/transcriptions, /v1/audio/translations,
/v1/moderations, /v1/rerank, /v1/completions and /v1/messages/count_tokens. These pass
through in the provider's own format, without translation, to models whose provider offers
them. GET /v1/models lists the models you can call: see Models.
Your first call in each format#
curl https://api.hixel.dev/v1/responses \
-H "Authorization: Bearer $HIXEL_API_KEY" \
-H "Content-Type: application/json" \
-H "x-hixel-customer: org_42" \
-H "x-hixel-member: user_7" \
-d '{ "model": "gpt-6.2-sol", "input": "Summarise this ticket in one line." }'import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.HIXEL_API_KEY,
baseURL: "https://api.hixel.dev/v1",
});
const response = await client.responses.create(
{ model: "gpt-6.2-sol", input: "Summarise this ticket in one line." },
{ headers: { "x-hixel-customer": "org_42", "x-hixel-member": "user_7" } },
);Authentication#
Send a key with the inference scope as Authorization: Bearer hx_sk_… or as
x-api-key: hx_sk_… (where the Anthropic SDK puts it). A browser or mobile app sends a
client token the same way instead. See
Authentication for keys and scopes.
Request headers#
| Header | What it does |
|---|---|
x-hixel-customer | Your id for the customer the request is for: 1 to 256 characters of visible ASCII, no spaces, not . or ... Its wallet pays and its limits apply. |
x-hixel-member | Your id for the person who made it, same rules. Recorded on the request, and member limits apply to it. |
x-hixel-tags | Up to 8 labels for your own reports. See Tags and caching. |
x-hixel-cache | Directives for the response cache, when the environment has it on. See Tags and caching. |
x-hixel-mock | Test environments only: steer the mock's answer. See Test environments. |
None of these is forwarded to the provider. A header that does not follow its rules is refused
with 400 and invalid_header, naming the header in param, before anything is charged.
An environment can require a customer on every request (Gateway → Request handling in the
dashboard). Then a request without x-hixel-customer is refused with customer_required. A key can also
be pinned to one customer: its requests act for that customer, may leave the header out, and
are refused with customer_mismatch if they name another.
Response headers#
| Header | Value |
|---|---|
x-hixel-request-id | The request's id, req_ and 32 hex characters. It is on the usage record and every event. |
x-hixel-model | The model that answered, by its name in the catalog (an alias resolves to the model it names) |
x-hixel-provider | The provider that answered |
x-hixel-attempts | How many provider calls the request took, when more than one |
x-hixel-cache | hit or miss, when the response cache applied |
x-hixel-mock | true when a test environment's mock answered |
x-ratelimit-* | Your own rate limits: see Limits |
Log x-hixel-request-id with your own request logs. It is the link between a response, its
usage record, its webhook events and its trace span.
Streaming#
Ask for a stream the way the format does ("stream": true); the gateway passes the server-sent
events through as they arrive. Usage is read off the stream on the way, so a streamed request is
metered and billed like any other.
For Chat Completions, the gateway asks the provider for the final usage chunk
(stream_options.include_usage) and, if you did not ask for it yourself, removes that chunk
before it reaches you, so your stream looks exactly as it would from the provider.
If the client disconnects, the gateway stops reading the provider's stream and records the
request with the outcome aborted. Some providers report usage only at the end of a stream;
when none was reported, the request is charged at the estimate the gateway reserved for it
before calling the provider.
Retries and fallbacks#
The gateway retries a failed provider call and can fall back to another deployment of the same
model, within the environment's routing policy (by default at most 3 attempts per request).
x-hixel-attempts tells you when that happened. Your own client should still retry on 429
and 503, honouring retry-after when it is present.
Errors#
The gateway's own refusals (a bad key, no balance, a limit reached) use the error envelope. Errors from the provider are passed through with their status and body, rewritten into your format when the request was translated. See Gateway errors.