Varity AI Gateway
The Varity AI Gateway is an OpenAI-compatible inference API. It speaks the same chat-completions wire format as the OpenAI API, so every OpenAI SDK, framework adapter, and agent runtime already knows how to talk to it. The integration is a one-line base-URL swap.
https://varity.app/v1Fastest Path
Section titled “Fastest Path”Set two variables and send a request. This is the whole integration.
curl https://varity.app/v1/chat/completions \ -H "Authorization: Bearer $VARITY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "glm-5-2", "messages": [ { "role": "user", "content": "Say hello in one sentence." } ] }'# pip install openaiimport osfrom openai import OpenAI
client = OpenAI( base_url="https://varity.app/v1", api_key=os.environ["VARITY_API_KEY"],)
response = client.chat.completions.create( model="glm-5-2", messages=[{"role": "user", "content": "Say hello in one sentence."}],)
print(response.choices[0].message.content)// npm install openaiimport OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://varity.app/v1", apiKey: process.env.VARITY_API_KEY,});
const response = await client.chat.completions.create({ model: "glm-5-2", messages: [{ role: "user", content: "Say hello in one sentence." }],});
console.log(response.choices[0].message.content);base_url / baseURL is the only line that differs from an OpenAI setup. Model
ids come from the Varity catalog, not OpenAI’s. See
Models for the full list.
Confirm The Gateway Before You Have A Key
Section titled “Confirm The Gateway Before You Have A Key”GET /v1/models is public. Run it right now, with no credential, and you get a
200 plus the live catalog:
curl https://varity.app/v1/models{ "object": "list", "data": [ { "id": "glm-5-2", "display_name": "GLM 5.2", "object": "model", "owned_by": "varity", "capabilities": { "chat_completions": true, "tool_calls": false, "streaming": true, "streaming_tool_calls": false }, "context_window": 1000000, "max_completion_tokens": 131072, "privacy": "private", "privacy_routes": ["private"], "availability": { "status": "available" }, "customer_pricing": { "status": "configured", "currency": "usd", "unit": "per_million_tokens", "input": 1.47, "output": 4.62, "cached_input": 1.47 } } ]}The gateway also exposes an unauthenticated health probe:
curl https://varity.app/health{ "status": "healthy", "service": "varity-gateway", "version": "1.13.49" }Authentication
Section titled “Authentication”Inference requests require a Varity API key sent as a bearer credential:
Authorization: Bearer $VARITY_API_KEYCreate keys in the Developer Portal settings page. Key plaintext is shown once at creation and is never returned again. The same key format is used across the Varity public API.
Auth is enforced on /v1/chat/completions. A request with no Authorization
header returns 401:
{ "error": { "message": "A Bearer API key is required.", "type": "authentication_error", "code": "authentication_required", "param": null, "retryable": false, "request_id": "516c24ef-ba5a-4e3d-8f32-0a609ae5d298" }}A malformed or revoked key returns 401 with code: "invalid_api_key" and the
message The API key is invalid or revoked.
Streaming
Section titled “Streaming”Set stream: true for server-sent events, exactly as with OpenAI. Every model in
the catalog reports "streaming": true.
curl https://varity.app/v1/chat/completions \ -H "Authorization: Bearer $VARITY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "glm-5-2", "stream": true, "messages": [ { "role": "user", "content": "Count to five." } ] }'stream = client.chat.completions.create( model="glm-5-2", messages=[{"role": "user", "content": "Count to five."}], stream=True,)
for chunk in stream: delta = chunk.choices[0].delta.content if delta: print(delta, end="")const stream = await client.chat.completions.create({ model: "glm-5-2", messages: [{ role: "user", content: "Count to five." }], stream: true,});
for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}Streaming tool calls are a narrower capability than streaming text, and are
only supported on some models. Check capabilities.streaming_tool_calls before
you combine stream: true with tools. See
Compatibility.
Errors
Section titled “Errors”Errors use the OpenAI error envelope, with two Varity additions: retryable and
request_id.
| Field | Meaning |
|---|---|
error.message | Human-readable description |
error.type | Error class, for example authentication_error |
error.code | Stable machine code, for example invalid_api_key |
error.param | Offending request field, or null |
error.retryable | Whether retrying the same request can succeed |
error.request_id | Correlation id, also returned as the x-request-id response header |
Quote request_id in any support request. It is present on both the response
body and the x-request-id header on every response, including successful ones.
Rate Limits
Section titled “Rate Limits”GET /v1/models returns standard rate-limit headers:
ratelimit-limit: 120ratelimit-policy: 120;w=60ratelimit-remaining: 119ratelimit-reset: 60That is 120 requests per 60-second window on the catalog endpoint. Read the
ratelimit-remaining and ratelimit-reset headers rather than hardcoding a
budget; the policy is served live and can change.
Next Steps
Section titled “Next Steps”- Models: the full live catalog with context windows, limits, and prices
- Compatibility: exactly what the OpenAI surface includes and excludes
- Public API Reference: the
/apiplatform contract for deploys and operations