API reference
VAL Router API
A REST API in the OpenAI and Anthropic formats. Point your base URL at the gateway, send your val-router- key, and keep the rest of your code.
On this page
01 Introduction
VAL Router is a hosted REST gateway for large language models. It speaks both the OpenAI and Anthropic wire formats from a single base URL, so you keep the SDK you already use and change two values: the base URL and the API key.
One val-router- key works for every endpoint. Requests are routed to healthy upstream providers with automatic failover, and usage is metered per key.
https://router.byvall.com/v1- Bearer val-router-... or X-API-Key
- OpenAI + Anthropic compatible
- 30 requests / min per key
New to the API? Start with the quick start, then read authentication and the endpoint reference.
02 Quick start
Three steps from zero to the first completion. If you already have a key, jump straight to step 3.
Get an API key
Register, open the dashboard and create a key. Keys look like val-router-... and work for both wire formats.
Point your SDK here
Set the client base URL to https://router.byvall.com/v1 and export your key as an environment variable.
Make a request
Call chat completions with any model id from GET /v1/models. The first response proves the wiring end to end.
First request
import openaiclient = openai.OpenAI( base_url="https://router.byvall.com/v1", api_key="$VALROUTER_API_KEY",)resp = client.chat.completions.create( model="deepseek/deepseek-v4.1-flash", messages=[{"role": "user", "content": "Hello!"}],)print(resp.choices[0].message.content)import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://router.byvall.com/v1", apiKey: process.env.VALROUTER_API_KEY,});const resp = await client.chat.completions.create({ model: "deepseek/deepseek-v4.1-flash", messages: [{ role: "user", content: "Hello!" }],});console.log(resp.choices[0].message.content);curl https://router.byvall.com/v1/chat/completions \ -H "Authorization: Bearer $VALROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek/deepseek-v4.1-flash", "messages": [{ "role": "user", "content": "Hello!" }] }'Model ids. Every key sees its own catalogue. Call GET /v1/models (see List models) and use an id from the response; the example above uses one that ships with every key.
03 Authentication
Every request is authenticated with your val-router- key. Send it as a Bearer token in the Authorization header (OpenAI convention) or in the X-API-Key header. Either works everywhere, on both wire formats.
GET https://router.byvall.com/v1/modelsAuthorization: Bearer val-router-...X-API-Key: val-router-...Key management
- Create, rotate and revoke keys from the dashboard.
- Keys are bound to a plan, a token balance or a PAYG balance.
- One key is enough: it authenticates OpenAI, Anthropic and the routing endpoints.
Keep the key secret. Treat val-router-... like a password. Anyone with the key spends your quota. Use environment variables, not client-side code, to store it.
04 Endpoint support
The gateway exposes one REST surface at https://router.byvall.com/v1. It passes the OpenAI and Anthropic formats through to healthy upstream providers, so your existing SDK code keeps working. All endpoints below require authentication.
OpenAI-compatible API
The OpenAI surface matches the official Clients. Point an OpenAI-style SDK at https://router.byvall.com/v1 and it works unchanged.
/v1/modelsLists the models available to your key: catalogue models, your combos and any Bansos public model. Each entry carries a context_window, USD pricing and a capabilities array.
curl https://router.byvall.com/v1/models \ -H "Authorization: Bearer $VALROUTER_API_KEY"Response sample
{ "object": "list", "data": [ { "id": "deepseek/deepseek-v4.1-flash", "object": "model", "created": 1763550000, "owned_by": "deepseek", "context_window": 1000000, "pricing": { "input": 0.3, "output": 1.2 }, "capabilities": ["chat", "streaming", "vision"] } ]}/v1/quotaReturns the key's entitlement: plan, expiry, RPM and parallel limits, token balance, allowed models and the last 30 days of usage. The same data you see in the dashboard.
curl https://router.byvall.com/v1/quota \ -H "Authorization: Bearer $VALROUTER_API_KEY"Response sample
{ "object": "quota", "key": { "id": 42, "name": "my-key", "kind": "subscription", "status": "active", "expires_at": 1795086000000, "rpm_limit": 30, "parallel_limit": 3, "token_balance": 0, "allowed_models": [] }, "plan": { "slug": "pro", "name": "Pro" }, "usage": { "requests_30d": 412, "tokens_30d": 1534821, "charge_30d": 2.31 }, "balance": 5.5, "bonus_tokens": 0, "valid": true}Quota vs balance. balance is your PAYG credit, bonus_tokens the prepaid token pool and usage the rolling 30-day history. A subscription key spends none of them until the plan expires.
/v1/chat/completionsThe workhorse endpoint: a standard chat completion in the OpenAI format. Use any model id from List models.
resp = client.chat.completions.create( model="deepseek/deepseek-v4-pro", messages=[ {"role": "system", "content": "You are a concise assistant."}, {"role": "user", "content": "Explain SSE in two sentences."}, ], temperature=0.7, max_tokens=512,)print(resp.choices[0].message.content)const resp = await client.chat.completions.create({ model: "deepseek/deepseek-v4-pro", messages: [ { role: "system", content: "You are a concise assistant." }, { role: "user", content: "Explain SSE in two sentences." }, ], temperature: 0.7, max_tokens: 512,});console.log(resp.choices[0].message.content);curl https://router.byvall.com/v1/chat/completions \ -H "Authorization: Bearer $VALROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek/deepseek-v4-pro", "messages": [ { "role": "system", "content": "You are a concise assistant." }, { "role": "user", "content": "Explain SSE in two sentences." } ], "temperature": 0.7, "max_tokens": 512 }'Request parameters
| Field | Type | Description |
|---|---|---|
model | string · required | Model id, e.g. deepseek/deepseek-v4-pro. |
messages | array · required | Conversation turns with role and content. |
temperature | number | Sampling temperature. Default 1. |
max_tokens | integer | Upper bound for the completion. |
stream | boolean | Stream the response over SSE. See Streaming. |
Response sample
{ "id": "chatcmpl-9f2c", "object": "chat.completion", "created": 1763550000, "model": "deepseek/deepseek-v4-pro", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Server-Sent Events push text to the client ..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 24, "completion_tokens": 41, "total_tokens": 65 }}/v1/responsesThe OpenAI Responses API. Use input instead of messages; the response carries output and output_text. Streaming is supported with stream: true.
resp = client.responses.create( model="z-ai/glm-5.2", input="Summarise the SSE spec in one line.",)print(resp.output_text)const resp = await client.responses.create({ model: "z-ai/glm-5.2", input: "Summarise the SSE spec in one line.",});console.log(resp.output_text);curl https://router.byvall.com/v1/chat/completions \ -H "Authorization: Bearer $VALROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "z-ai/glm-5.2", "input": "Summarise the SSE spec in one line." }'Response sample
{ "id": "resp_4b1e", "object": "response", "created": 1763550120, "model": "z-ai/glm-5.2", "output": [ { "type": "message", "role": "assistant", "content": [{ "type": "output_text", "text": "SSE is a ..." }] } ], "usage": { "input_tokens": 18, "output_tokens": 27, "total_tokens": 45 }}Anthropic-compatible API
The Anthropic surface matches the Messages API. Use the Anthropic SDK, set the base URL and key, and add the anthropic-version header.
/v1/messagesA standard Anthropic Messages request. Required header: anthropic-version: 2023-06-01. The gateway bridges the response back into the native Anthropic shape, including SSE events when streaming.
import anthropicclient = anthropic.Anthropic( base_url="https://router.byvall.com/v1", api_key="$VALROUTER_API_KEY",)message = client.messages.create( model="anthropic/claude-sonnet-5", max_tokens=512, messages=[{"role": "user", "content": "Hello!"}],)print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ baseURL: "https://router.byvall.com/v1", apiKey: process.env.VALROUTER_API_KEY,});const message = await client.messages.create({ model: "anthropic/claude-sonnet-5", max_tokens: 512, messages: [{ role: "user", content: "Hello!" }],});console.log(message.content[0].text);curl https://router.byvall.com/v1/messages \ -H "x-api-key: $VALROUTER_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "anthropic/claude-sonnet-5", "max_tokens": 512, "messages": [{ "role": "user", "content": "Hello!" }] }'Request parameters
| Field | Type | Description |
|---|---|---|
model | string · required | Model id, e.g. anthropic/claude-sonnet-5. |
max_tokens | integer · required | Upper bound for the completion. |
messages | array · required | Conversation turns with role and content. |
system | string | System prompt, passed separately from the turns. |
Response sample
{ "id": "msg_01XFDUDYJgAACzvnptvVoaTre", "type": "message", "role": "assistant", "model": "anthropic/claude-sonnet-5", "content": [ { "type": "text", "text": "Hello! How can I help you today?" } ], "stop_reason": "end_turn", "usage": { "input_tokens": 12, "output_tokens": 19 }}Pass-through, not passthrough limits. The gateway proxies the OpenAI /v1/completions, embedding, moderation and image endpoints when the provider supports them. The four above are the ones every key can rely on.
05 Streaming (SSE)
Add "stream": true to any chat, responses or messages request and the gateway answers with Content-Type: text/event-stream. Tokens arrive as Server-Sent Events as the upstream produces them.
OpenAI-shaped stream
Chunks follow the chat.completion.chunk object. Each data: line carries one delta; the stream ends with data: [DONE].
HTTP/1.1 200 OKContent-Type: text/event-streamCache-Control: no-cachedata: {"id":"chatcmpl-9f2c","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"}}]}data: {"id":"chatcmpl-9f2c","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1..."}}]}data: {"id":"chatcmpl-9f2c","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"2..."},"finish_reason":null}]}data: [DONE]stream = client.chat.completions.create( model="deepseek/deepseek-v4.1-flash", messages=[{"role": "user", "content": "Count to five."}], stream=True,)for chunk in stream: delta = chunk.choices[0].delta.content if delta: print(delta, end="", flush=True)const stream = await client.chat.completions.create({ model: "deepseek/deepseek-v4.1-flash", messages: [{ role: "user", content: "Count to five." }], stream: true,});for await (const chunk of stream) { const delta = chunk.choices[0]?.delta?.content; if (delta) process.stdout.write(delta);}curl https://router.byvall.com/v1/chat/completions \ -H "Authorization: Bearer $VALROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek/deepseek-v4.1-flash", "messages": [{ "role": "user", "content": "Count to five." }], "stream": true }'Anthropic-shaped stream
On /v1/messages the gateway emits native Anthropic events: message_start, content_block_start, content_block_delta, content_block_stop and message_stop.
event: message_startdata: {"type":"message_start","message":{"id":"msg_01XFDUDYJgAC","role":"assistant","content":[]}}event: content_block_startdata: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}event: content_block_deltadata: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}event: message_stopdata: {"type":"message_stop"}Clients handle the parsing. The official OpenAI and Anthropic SDKs parse these frames for you. Consume the stream object (for chunk in stream / for await (const chunk of stream)) instead of reading the raw socket.
Disconnects. If the client closes the connection mid-stream the gateway stops billing and records client_disconnect. Tokens already generated are still charged.
06 Error codes
Errors use the standard OpenAI envelope. On Anthropic-shaped endpoints the same failure is wrapped in the Anthropic { type: "error", error: {...} } shape instead.
{ "error": { "message": "Incorrect API key provided...", "type": "invalid_request_error", "code": "invalid_api_key", "param": null }}| Status | Code | Meaning & how to fix |
|---|---|---|
| 400 | invalid_json, missing_model, invalid_request | Malformed body, missing model, or a parameter the endpoint rejects. Fix the request and retry. |
| 401 | missing_api_key, invalid_api_key | No key, or the key is wrong, revoked or malformed. Check the dashboard value. |
| 402 | insufficient_quota | Token balance or subscription quota is exhausted. Top up or renew. |
| 403 | model_not_allowed | The model is not in your plan, or an IP-binding rule blocked the request. |
| 404 | model_not_found, not_found | Unknown endpoint or model id. List models for valid ids. |
| 429 | rate_limit_exceeded | Hard cap hit. Fair use queues instead of refusing; see Rate limits. |
| 499 | client_disconnect | The client closed the connection mid-request or mid-stream. |
| 503 | overloaded, capacity_unavailable, no_healthy_key | Upstreams saturated or no healthy key available. Retry shortly; the response may carry Retry-After. |
| 500 · 502 | upstream_error | An upstream provider failed. Retry; the gateway itself keeps running. |
Error messages may carry a shop hint. Quota refusals can include an operator-sentenced hint (for example a link to the shop) appended to the message. Treat it as guidance, not part of the error schema.
07 Rate limits
One fair-use limit protects every key: 30 requests per minute. When the window fills, the request is queued and served in turn — not refused — so a burst of traffic delays instead of failing.
How the queue works
- Requests inside the rolling 60-second window are served immediately.
- Once the window fills, the request waits for a free slot (queue depth is bounded).
- If the queue is full or the wait times out, the request is refused with 429 and a
Retry-Afterheader telling you exactly how long to back off.
Hard caps
No hourly, weekly or monthly request caps exist. A plan's parallel sessions ceiling (how many requests can run at once) and the fair-use RPM are the only throughput limits. Admin-assigned per-key caps (per-minute, per-hour, per-day, tokens-per-minute) can tighten them further — GET /v1/quota reports the effective values.
HTTP/1.1 429 Too Many RequestsRetry-After: 8{ "error": { "message": "Rate limit reached; the request is queued.", "type": "rate_limit_exceeded", "code": "rate_limit_exceeded", "param": null }}Best practices
- Retry 429 and 503 with exponential backoff; honour
Retry-Afterwhen present. - Prefer streaming for long generations — the connection stays busy and billing is fairer.
- Check
GET /v1/quotabefore large batches instead of probing with requests.
You are rarely refused. The design goal is a queued request, not a failed one. A client that retries on 429 and honours Retry-After will almost never see a hard failure under normal load.