# 1Inference API OpenAI-compatible chat, image, and text-to-speech API billed in Indonesian Rupiah. Humans browse the guide at https://1inference.com/docs. This file is the compact version for agents and scripts. Base URL: `https://api.1inference.com/v1` Auth header: `Authorization: Bearer sk_...` Create a key at https://1inference.com/dashboard/api-keys. Keys start with `sk_` and are shown once. ## Endpoints | Method | Path | Status | Notes | | --- | --- | --- | --- | | POST | `/v1/chat/completions` | available | OpenAI Chat Completions shape, JSON or SSE | | POST | `/v1/images/generations` | available | OpenAI Image Generation shape | | POST | `/v1/audio/speech` | available | Binary audio response | | GET | `/v1/models` | available | Catalog with Rupiah prices | | GET | `/v1/models/{id}` | available | One model from the same cached snapshot | | POST | `/v1/embeddings` | not available | Returns 503 | | POST | `/v1/audio/transcriptions` | not available | Returns 503 | | POST | `/v1/completions` | not available | Returns 503 | | POST | `/v1/video/generations` | not available | Returns 503 | | POST | `/v1/music/generations` | not available | Returns 503 | Model IDs are the plain catalog names, for example `deepseek-v4.1-flash`, `gpt-4o-mini`, `claude-sonnet-4.5`. Read `GET /v1/models` for the current list; examples here can age. ## Chat completions ```bash curl https://api.1inference.com/v1/chat/completions \ -H "Authorization: Bearer sk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-v4.1-flash", "messages": [{"role": "user", "content": "Halo!"}], "max_tokens": 512, "stream": false }' ``` Parameters: | Name | Type | Required | Notes | | --- | --- | --- | --- | | `model` | string | yes | Catalog ID, max 128 characters | | `messages` | array | yes | At least one message with `role` and `content` | | `stream` | boolean | no | Default `false`. `true` returns SSE | | `max_tokens` | integer | no | Older alias of `max_completion_tokens` | | `max_completion_tokens` | integer | no | When neither field is set the server sends 4096 | | `temperature` | number | no | 0 to 2. Model default when omitted | | `top_p` | number | no | 0 to 1. Model default when omitted | | `stop` | string or array | no | Stop sequences | | `tools` | array | no | OpenAI function format | | `tool_choice` | string or object | no | `auto`, `none`, `required`, or one tool | | `response_format` | object | no | For example `{"type": "json_object"}` | | `stream_options` | object | no | For example `{"include_usage": true}` | Response: ```json { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1713200000, "model": "deepseek-v4.1-flash", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Halo!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 12, "completion_tokens": 9, "total_tokens": 21 } } ``` The answer text is at `choices[0].message.content`. With `stream: true` the body is `text/event-stream` in OpenAI chunk format and normally ends with `data: [DONE]`. The gateway stops retrying once the first chunk reaches the client. ## Models ```bash curl https://api.1inference.com/v1/models \ -H "Authorization: Bearer sk_your_api_key" ``` Each entry has `id`, `name`, `pricing`, `discount_percent`, and `seller_count`, plus `media_unit` for image and audio models. The payload also carries `exchange_rate` (USD to IDR). ## Image generation ```json { "model": "venice-z-image-turbo", "prompt": "Matahari terbenam di atas pulau tropis", "n": 1, "size": "1024x1024", "quality": "high", "response_format": "url" } ``` `n` must be 1; the upstream returns 400 for larger values. `response_format` is `b64_json` by default, and `url` depends on the model. Image models bill per token, per image, or per megapixel; `media_unit` on the catalog entry says which. ## Text to speech ```json { "model": "tts-minimax-speech-02-hd", "input": "Halo, selamat datang di 1Inference!", "voice": "WiseWoman", "response_format": "mp3", "speed": 1, "streaming": false } ``` The response body is binary audio and `Content-Type` follows the format (for example `audio/mpeg`). Upstream accepts `mp3`, `opus`, `aac`, and `flac`; it rejects `wav` and `pcm`. `voice` must belong to the chosen model. No endpoint lists voices, so check the model documentation before relying on a name. ## Errors ```json { "error": { "message": "Insufficient balance", "type": "invalid_request_error", "code": "insufficient_balance", "status": 402 }, "request_id": "req_01J..." } ``` `request_id` is present when the gateway has one. Messages are in English. | HTTP | Code | Type | Meaning | | --- | --- | --- | --- | | 400 | `invalid_request` | `invalid_request_error` | Bad field or malformed JSON | | 400 | `model_too_long` | `invalid_request_error` | `model` is longer than 128 characters | | 401 | `invalid_api_key` | `invalid_request_error` | Key missing, malformed, revoked, or unknown | | 401 | `key_expired` | `invalid_request_error` | Key past its expiry | | 402 | `insufficient_balance` | `invalid_request_error` | Balance below the estimated cost | | 402 | `reservation_expired` | `invalid_request_error` | Hold expired before the request finished | | 403 | `model_not_available` | `invalid_request_error` | Model closed or blocked | | 404 | `model_not_found` | `invalid_request_error` | No seller offers that model ID | | 429 | `rate_limit_exceeded` | `rate_limit_error` | A rate or concurrency limit was hit | | 429 | `provider_rate_limited` | `provider_error` | Upstream rate limited the request | | 500 | `internal_error` | `server_error` | Unexpected server error | | 502 | `provider_error` | `provider_error` | Upstream provider error | | 503 | `provider_unavailable` | `server_error` | No upstream reachable | | 503 | `exchange_rate_unavailable` | `server_error` | USD to IDR rate unavailable | | 503 | `authentication_service_unavailable` | `server_error` | Auth service unreachable | | 503 | `minimum_discount_not_met` | `server_error` | No seller meets the minimum discount | | 504 | `provider_timeout` | `provider_error` | Upstream timed out | Retries: the gateway retries 500, 502, 504, and timeouts inside a provider tier after 2 to 3 seconds, then moves to the next tier. It moves to the next tier immediately on 429 and 503. It returns 400, 401, 402, 403, and 404 unchanged. No `Retry-After` header is sent. Do not replay 400, 401, 402, 403, or 404 blindly; fix the request or the balance first. Billing: a request that succeeded and is sent again is billed twice. A request that failed at the upstream can still be billed for work the upstream did, especially images, TTS, and cancelled streams. Check the usage page before replaying a step. ## Rate limits | Layer | Scope | Limit | Window | | --- | --- | --- | --- | | Global | all users | 20,000 requests | 1 minute | | Per user | user ID | 2,000 requests | 1 minute | | Per API key | API key | 1,000 requests | 1 minute | | Per model | model name | 2,000 requests | 1 minute | | Concurrency | user ID | 400 open requests | while running | No `X-RateLimit` headers are sent. Read the 429 body and back off. The limits are configuration, so treat this table as current defaults. ## Top up Minimum top up is Rp10.000, paid by QRIS or card through Midtrans. A top up is `pending` while it waits, then `completed` after payment settles or `failed` when the payment expires. Credit is written before the status becomes `completed`. ## Platform integrations ### Shared rules for n8n, Make, and Zapier - Keep `stream: false` on HTTP steps. Make and Zapier read one JSON body and do not render SSE; n8n's Chat Model node handles SSE itself, but an HTTP Request node still needs a plain response. - Map the answer from `choices[0].message.content`, not the whole body. - Set `max_tokens` between 256 and 1024 so the answer finishes inside the platform timeout. - Timeouts: Zapier 30 s per step, Make 40 s by default (300 s maximum), n8n per node. - Every retry is a new request and is billed again. Retry only after reading the error. - Put the key in the platform credential or a step header only editors can see, never in the JSON body or a prompt. Common failures: 401 `invalid_api_key` (header missing or `Bearer` left out), 402 `insufficient_balance` (top up), 404 `model_not_found` (refresh the ID from `GET /v1/models`), 400 `invalid_request` (broken JSON or wrong types), 429 (wait and back off), timeout (lower `max_tokens` or pick a faster model), empty answer (wrong mapping path or `stream: true`). ### n8n 1. Add a trigger such as `When chat message received`. 2. Add an `AI Agent` node and connect the trigger to its main input. 3. On the `Chat Model` port add an `OpenAI Chat Model` sub-node. 4. Create an OpenAI credential: API key is the `sk_` key, Base URL is `https://api.1inference.com/v1`. The Base URL must end in `/v1`. 5. Pick a model from the list, or switch the Model field to expression mode and paste the catalog ID. 6. Run the workflow once. If the model dropdown stays empty, type the ID. The Chat Model node returns text only; for images or audio use an `HTTP Request` node with the same credential. ### Make 1. Add `HTTP > Make a request`. 2. Method `POST`, URL `https://api.1inference.com/v1/chat/completions`. 3. Headers: `Authorization: Bearer sk_...` and `Content-Type: application/json`. 4. Body type `Raw`, content type `JSON`, paste the JSON body. 5. Turn on `Parse response` so the reply becomes fields, not a text blob. 6. Map `choices`, first item, `message.content` into the next module. Default timeout is 40 seconds (300 maximum). Add an error handler route for 402 and 429 instead of a blind retry. ### Zapier 1. Add `Webhooks by Zapier > Custom Request`. 2. Method `POST`, URL `https://api.1inference.com/v1/chat/completions`. 3. Headers: `Authorization: Bearer sk_...` and `Content-Type: application/json`. 4. Paste the JSON body in `Data`. Set `Data Pass-Through` to `No`, `Unflatten` to `No`, and `Return Raw Response` to `No` so Zapier parses the reply. 5. Map `choices`, first item, `message.content` into the next step. A Zap step has 30 seconds. `AI by Zapier` calls OpenAI directly and cannot be pointed at this API. The key lives in the Custom Request header, so restrict who can edit the Zap. ## Pricing and payment Prices are in Rupiah with USD alongside, from `GET /v1/models`. Chat bills per token, images per token, image, or megapixel, and TTS per character. The catalog price is the final price you pay; no subscription fee applies. ## Verification The rate limits, top-up minimum, and error codes in this file are checked against the backend source by `frontend/scripts/check-docs-truth.mjs`. Run it with `npm run docs:check` from `frontend/`.