# ApiX Complete documentation. Spanish: https://vipp.apixx.playersito.cat/docs/es.md ## Overview ApiX puts several AI providers behind one endpoint and one key. It speaks the OpenAI API and the Anthropic API, so most SDKs and clients work by changing the base URL. There is also a playground: open `/playground`, paste a key and chat with any model in the catalog (the key stays in an HttpOnly cookie). ```bash export APIX_BASE="https://vipp.apixx.playersito.cat" export APIX_KEY="apix-..." ``` Send your first request: ```bash curl "$APIX_BASE/v1/chat/completions" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{ "model": "4/glm-5.3-flash", "messages": [{"role": "user", "content": "Say hello"}] }' ``` ```json { "id": "chatcmpl_...", "object": "chat.completion", "model": "4/glm-5.3-flash", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello!"}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 9, "completion_tokens": 3, "total_tokens": 12} } ``` ### What the API covers | You want | Endpoint | |---|---| | Chat, vision, tools, reasoning | `POST /v1/chat/completions` | | Anthropic clients | `POST /v1/messages` | | Codex-style clients | `POST /v1/responses` | | Images | `POST /v1/images/generations` | | Text to speech | `POST /v1/audio/speech` | | Speech to text | `POST /v1/audio/transcriptions` | | Video | `POST /v1/videos` | An endpoint only works when a model in the catalog supports that operation. `GET /apix/models/info` tells you with `operations..enabled` (for example `operations.transcriptions.enabled`), and `/v1/models?output_modalities=` filters the list by what the model produces. ### Model ids Every model is `/`, for example `4/glm-5.3-flash` or `1/heygen-voice-1-turbo:free`. Browse them with `GET /v1/models`; anything that is not in the catalog returns `404 MODEL_NOT_FOUND`. See [Models](https://vipp.apixx.playersito.cat/docs/models). ## Authentication Send your key on every request. Any of these headers works: | Header | Usually used by | |---|---| | `Authorization: Bearer ` | OpenAI SDK, curl | | `x-api-key: ` | Anthropic SDK, Claude clients | | `x-apix-key: ` | Alias | ```bash curl "$APIX_BASE/v1/models" -H "Authorization: Bearer $APIX_KEY" ``` A missing or unknown key returns `401 INVALID_ACCESS_KEY`. Repeated bad keys from one IP return `429 TOO_MANY_FAILED_ATTEMPTS`. Keys carry their own limits: allowed models, requests per day, tokens per day and spend per day. You can read them from `GET /apix/usage` or from the `x-apix-*` response headers. Never ship a key in a browser or mobile app: call ApiX from your backend. ## Models | Endpoint | Returns | |---|---| | `GET /v1/models` | OpenAI-style list | | `GET /v1/models/count` | `{"data":{"count":N}}` | | `GET /v1/model/{id}` | one model: context, modalities, price | | `GET /apix/models/info` | full catalog with capabilities and status | `/v1/models` filters by output modality: ```bash curl "$APIX_BASE/v1/models" -H "Authorization: Bearer $APIX_KEY" curl "$APIX_BASE/v1/models?output_modalities=image" -H "Authorization: Bearer $APIX_KEY" ``` Values: `text` (default, returns everything), `image`, `video`, `speech`, `transcription`, `embeddings`. ### What a model entry looks like `GET /apix/models/info` is the one to use when building a UI: ```json { "id": "4/glm-5.3-flash", "provider": "4", "context": 1000000, "max_output_tokens": 131072, "input_modalities": ["text"], "output_modalities": ["text"], "supports_tools": true, "protocols": {"openai_chat": "native", "anthropic_messages": "native"}, "operations": { "chat": {"enabled": true, "source": "legacy"}, "messages": {"enabled": true, "source": "legacy"}, "responses": {"enabled": false, "source": "unspecified"} }, "input_price_per_mtok": 0.15, "output_price_per_mtok": 0.5, "going_away": null, "zdr": true } ``` `zdr` is the Zero Data Retention badge of the dashboard: `true` (no retention), `"warning"` (safety retention), `false` (retains data), `null` (unknown). When a provider serves the model through several endpoints the entry also carries `"endpoints": [{"name": "primary", "label": "provider-a", "zdr": true}, ...]`; the `name` is what the `endpoint` field accepts, and `zdr` follows the first one (the main endpoint). Check `operations..enabled` and `supports_tools` before using a feature. This endpoint is the **catalog**: it carries no live status (only `going_away`). For up/down see [Model status](https://vipp.apixx.playersito.cat/docs/status). ### Aliases Some ids are aliases, not single models: `auto`, `global`, `global/best` and a few names like `deepseek-pro` or `qwen`. An alias points to a chain of models, so if the first one fails the next is tried automatically. The response keeps the alias id on purpose (`x-apix-model`), so you don't need to know which provider served it. ## Chat Completions `POST /v1/chat/completions` is the OpenAI Chat Completions API, with the same request and response shapes. | Field | Notes | |---|---| | `model` | required, public id | | `messages` | `system`, `user`, `assistant`, `tool` | | `stream` | `true` for Server-Sent Events | | `max_tokens` / `max_completion_tokens` / `max_output_tokens` | any of the three | | `temperature`, `top_p`, `seed`, `stop` | forwarded when the model supports them | | `tools`, `tool_choice`, `parallel_tool_calls` | see [Tools](https://vipp.apixx.playersito.cat/docs/tools) | | `response_format` | `{"type":"json_object"}` or a JSON schema | | `reasoning_effort` | `low`, `medium`, `high` on reasoning models | | `stream_options.include_usage` | adds a final chunk with usage | ```bash curl "$APIX_BASE/v1/chat/completions" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{ "model": "4/glm-5.3-flash", "messages": [ {"role": "system", "content": "Answer in one sentence."}, {"role": "user", "content": "What is a gateway?"} ], "max_tokens": 200 }' ``` A JSON reply carries `x-apix-input-tokens`, `x-apix-output-tokens`, `x-apix-total-tokens` and `x-apix-spend-usd`. In streaming those headers cannot be sent (usage is known at the end): read the final `: apix {...}` comment instead. If a model does not support a parameter the provider may reject it with `400`. The catalog lists what each model accepts in `supported_parameters`. ## Streaming Set `stream: true` and read Server-Sent Events: `data: {...}` chunks and a final `data: [DONE]`. ```python import json, os, requests res = requests.post( os.environ["APIX_BASE"] + "/v1/chat/completions", headers={"Authorization": "Bearer " + os.environ["APIX_KEY"]}, json={ "model": "4/glm-5.3-flash", "stream": True, "stream_options": {"include_usage": True}, "messages": [{"role": "user", "content": "Count to 20"}], }, stream=True, ) for line in res.iter_lines(decode_unicode=True): if not line or not line.startswith("data: "): continue payload = line[6:] if payload == "[DONE]": break chunk = json.loads(payload) print(chunk["choices"][0]["delta"].get("content", ""), end="") ``` ### Details - `/v1/messages` streams Anthropic events; `/v1/responses` streams Responses events. - With `stream_options.include_usage` the last chat chunk carries `usage`. - The stream ends with a comment line `: apix {...}` with usage and spend. SSE clients ignore comments; parse it if you want the cost. - ApiX sends `X-Accel-Buffering: no` so nginx does not hold the chunks. If you run your own proxy, disable response buffering there too. ## Tools Standard OpenAI function calling: declare functions, read `tool_calls`, send the result back with `role: "tool"`. ```bash curl "$APIX_BASE/v1/chat/completions" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{ "model": "2/kimi-k3", "messages": [{"role": "user", "content": "Weather in Caracas?"}], "tools": [{ "type": "function", "function": { "name": "get_weather", "description": "Current weather", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"] } } }] }' ``` The answer has `finish_reason: "tool_calls"` and: ```json { "tool_calls": [{ "id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\":\"Caracas\"}"} }] } ``` Send the result back and ask again: ```json {"role": "tool", "tool_call_id": "call_1", "content": "{\"temp_c\":27}"} ``` `parallel_tool_calls: false` forces one call at a time. In Anthropic clients this is `tool_use` and `tool_result` blocks; ApiX translates both ways. ## Reasoning Reasoning models accept `reasoning_effort` (`low`, `medium`, `high`) and return their thinking separately from the answer: | Protocol | Where the reasoning is | |---|---| | Chat | `message.reasoning_content` (`delta.reasoning_content` while streaming) | | Anthropic | `thinking` blocks | | Usage | `usage.completion_tokens_details.reasoning_tokens` | Reasoning tokens count against `max_tokens`. A very small limit can be spent thinking, leaving `content` empty and `finish_reason: "length"`. ## Prompt caching Providers cache the beginning of a prompt so repeated turns are cheaper and faster. Most providers do it on their own. A few need an explicit marker (`cache_control`): Anthropic, Alibaba/Qwen and Gemini. ApiX adds that marker for you on those models. ### Automatic When the model needs explicit breakpoints and your request has none of its own, ApiX marks two places: the end of the system prompt and the last text block. They are the parts that repeat in a conversation, so the next turn reads them from cache. The minimum length depends on the model (roughly 1,024–4,096 tokens depending on the family; the gateway uses each provider's documented minimum). Below that nothing is cached, and a marker there would only pay for the write. On providers that cache automatically, ApiX does **not** touch the body: adding a marker there does nothing and would break the provider's response cache. ### Turn it off ```json {"prompt_cache_options": {"mode": "off"}} ``` Also accepted: `{"cache_control": {"type": "none"}}`, `{"prompt_cache_options": {"disabled": true}}`, `{"apix_prompt_cache": "off"}`, or the server-wide `APIX_PROMPT_CACHE=off`. Your own breakpoints always win: if you send `cache_control` anywhere, ApiX does not add or move anything. ### TTL By default the provider decides (usually 5 minutes). A longer TTL is opt-in: ```bash APIX_CACHE_TTL=1h ``` `1h` costs more to write (Anthropic charges 2x instead of 1.25x), so use it for long sessions, not one-shot requests. A model can also pin its own TTL in the catalog. ### What it saves Cache reads are billed at a fraction of normal input. You can see them in `usage`: `prompt_tokens_details.cached_tokens` (OpenAI style), `cache_read_input_tokens` and `cache_creation_input_tokens` (Anthropic style). `GET /apix/usage` totals them as `cache_read_tokens`, `cache_write_tokens` and `cache_saved_usd`. ### Response cache For models that declare a response cache, ApiX asks the provider to cache the whole reply. Sending the exact same request again within the TTL returns the stored response instead of running the model. ## Vision Models with the `image` input modality read images. Send an HTTPS URL or a base64 data URL: ```json { "model": "3/qwen-3.8-27b:free", "messages": [{ "role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0..."}} ] }] } ``` Anthropic clients use the `image` block: ```json {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}} ``` Keys have media limits per request (`max_media_bytes_per_request`, `max_media_units_per_request`). Going over returns `400 MEDIA_BYTES_EXCEEDED` or `400 MEDIA_UNITS_EXCEEDED`. ## Responses API `POST /v1/responses` is the OpenAI Responses API, used by Codex-style clients. | Field | Notes | |---|---| | `model` | public id | | `input` | string or a list of input items | | `instructions` | system prompt | | `max_output_tokens` | output cap | | `tools` | function tools | | `stream` | Responses events | ```bash curl "$APIX_BASE/v1/responses" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{"model": "2/glm-5.3-flash", "input": "Explain SSE in one line."}' ``` ApiX chooses the path per model: providers that speak Responses natively are used as-is; the rest are converted to chat and back. Streaming works in both cases. ## Messages (Anthropic) `POST /v1/messages` is the Anthropic Messages API, for Claude Code, the Anthropic SDK and most agent frameworks. ```bash curl "$APIX_BASE/v1/messages" \ -H "x-api-key: $APIX_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "4/glm-5.3-flash", "max_tokens": 256, "system": "Answer in one sentence.", "messages": [{"role": "user", "content": "Hello"}] }' ``` Supported: `system`, content blocks (`text`, `image`, `tool_use`, `tool_result`, `thinking`), `tools` with the Anthropic schema, `tool_choice`, `stop_sequences`, `temperature`, `top_p`, `top_k` (when the model supports it), and streaming with `message_start`, `content_block_start/delta/stop`, `message_delta` and `message_stop`. ### Count tokens `POST /v1/messages/count_tokens` with the same body returns `{"input_tokens": N}`. ```python from anthropic import Anthropic client = Anthropic(api_key="apix-...", base_url="https://your-host") message = client.messages.create( model="4/glm-5.3-flash", max_tokens=256, messages=[{"role": "user", "content": "Hello"}], ) ``` ## Images | Endpoint | Body | |---|---| | `POST /v1/images/generations` | JSON: `model`, `prompt`, `n`, `size`, `response_format` | | `POST /v1/images/edits` | multipart: `image`, `prompt`, optional `mask` | | `POST /v1/images/variations` | multipart: `image` | ```bash curl "$APIX_BASE/v1/images/generations" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{"model": "", "prompt": "a lighthouse at dusk", "n": 1, "size": "1024x1024"}' ``` The model must generate images: `GET /v1/models?output_modalities=image`. The provider decides the reply (`b64_json` or `url`, depending on `response_format`). ## Text to speech `POST /v1/audio/speech` returns raw audio bytes. ```bash curl "$APIX_BASE/v1/audio/speech" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{ "model": "1/heygen-voice-1-turbo:free", "input": "Hello, this is a test.", "voice": "nadine" }' --output voice.pcm ``` | Field | Notes | |---|---| | `input` | text to read | | `voice` | one of the model voices | | `response_format` | the catalog value is enforced (`pcm` here; HeyGen rejects `mp3`) | The reply has `Content-Type: audio/pcm;rate=44100;channels=1` and the generation id in `X-Generation-Id`. HeyGen voices: `nadine`, `tabitha`, `bram`, `gareth`, `noelle`, `meredith`, `sabrina`, `lucian`, `weston`, `vincent`. ### Voice cloning Send a reference recording and its transcript instead of `voice`: ```json { "model": "1/heygen-voice-1-turbo:free", "input": "This is a clone test.", "input_references": [ {"type": "input_audio", "input_audio": {"data": "data:audio/wav;base64,UklGR..."}}, {"type": "text", "text": "Transcript of the reference recording."} ] } ``` One to three clips. Each clip can be followed by its transcript; you may also add one image as a scene reference. Nothing is stored server-side. To use a voice you already cloned in your provider account, connect your key there (BYOK) and pass its id as `voice`. ## Speech to text `POST /v1/audio/transcriptions` with `multipart/form-data`: ```bash curl "$APIX_BASE/v1/audio/transcriptions" \ -H "Authorization: Bearer $APIX_KEY" \ -F "file=@meeting.mp3" \ -F "model=" \ -F "language=es" \ -F "response_format=json" ``` `response_format` is forwarded to the provider; it usually accepts `json`, `text`, `srt` or `verbose_json`. An optional `prompt` biases vocabulary (names, jargon). The model must declare `operations.transcriptions.enabled`; otherwise you get `400 UNSUPPORTED_OPERATION`. ## Videos | Endpoint | What it does | |---|---| | `POST /v1/videos` | creates a job and returns `{id, status}` | | `GET /v1/videos/{id}` | status and progress | | `GET /v1/videos/{id}/status` | same, explicit route | | `GET /v1/videos/{id}/content` | the video bytes when ready | | `POST /v1/videos/{id}/cancel` | cancels the job | ```bash curl "$APIX_BASE/v1/videos" \ -H "Authorization: Bearer $APIX_KEY" \ -H "content-type: application/json" \ -d '{"model": "