Skip to content
Chat completions

Chat completions

The reference for the chat completions and models routes, their fields, responses, limits and errors.

The API answers chat completions from your organization's published models, in OpenAI's format. For a first request, see the API quickstart.

Route What it does
POST /v1/chat/completions Answers a conversation, whole or streamed.
GET /v1/models Lists the published models the key may call.

The API base URL is https://api.tensorant.io/v1, also shown at the top of API keys.

Authentication

Send your API key in the Authorization header of every request:

text
Authorization: Bearer YOUR_API_KEY

A key reaches only its organization's published models, and only those it may call. A missing, revoked or expired key gets 401 invalid_api_key.

The request

bash
curl https://api.tensorant.io/v1/chat/completions \
  -H "Authorization: Bearer $TENSORANT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-name",
    "messages": [
      {"role": "system", "content": "Answer in one sentence."},
      {"role": "user", "content": "What is a LoRA adapter?"}
    ],
    "max_tokens": 200,
    "temperature": 0.7
  }'

A field from the table below set to null counts as not sent.

Fields

Field Default What it does
model Required The name of a published model.
messages Required The conversation, 1 to 101 messages. See Messages.
max_tokens 512 The longest answer in tokens, an integer from 1 to 8,192.
max_completion_tokens None OpenAI's newer name for max_tokens. Wins when both are sent.
temperature 0 From 0 to 2. At 0 the model gives its most likely answer; raise it for varied answers.
top_p 1 Above 0 and at most 1.
stop None A string, or up to 4 strings of 1 to 64 characters. The model stops when it writes one.
seed None An integer whose absolute value is less than 2⁶³. The same seed and request can give the same answer.
frequency_penalty None A number from −2 to 2. Above 0, a token is less likely the more often it already appeared, so the answer repeats itself less.
presence_penalty None A number from −2 to 2. Above 0, a token that already appeared at all is less likely, so the answer moves on to new topics.
response_format None Makes the answer one JSON object, or JSON that matches your schema. See Response format.
reasoning_effort None none, minimal, low, medium, high or xhigh: how long a reasoning model, such as gpt-oss, thinks before it answers. On Qwen3 and Gemma 4 models, none turns thinking off. Models whose chat template doesn't use it ignore it.
n 1 Must be 1. Send several requests for several answers.
stream false true sends the answer as it is written. See Streaming.
stream_options None Only with stream: true. {"include_usage": true} adds a last chunk with the token counts.
user None Accepted for compatibility, and ignored. Must be a string.

Send whole numbers as integers: 100.0 is refused for max_tokens.

Fields that are refused

Any other field gets 400 unsupported_parameter, even when it is null. The message names it (the first alphabetically, if there are several), so you never assume something was applied when it was not. This includes OpenAI's tools, tool_choice, functions, logprobs, top_logprobs and logit_bias. Remove the field and send again.

Messages

Each message has exactly two fields:

  • role: system, user or assistant.
  • content: a string, or a list of parts:
    • {"type": "text", "text": "..."} in any message.
    • {"type": "image_url", "image_url": {"url": "..."}} in user messages, for a vision model. See Images.

A name field, a tool or developer role, or an empty list is refused with 400 invalid_request.

The conversation with its images must fit the model's context length, and so must max_tokens on its own. If either is longer, you get 400 model_refused. When the conversation fits but leaves less room than max_tokens, the answer stops at the end of the context, with finish_reason length.

Response format

response_format makes the model answer in JSON:

  • {"type": "json_object"}: the answer is one JSON object. Ask for JSON in the messages as well.
  • {"type": "json_schema", "json_schema": {"name": "...", "schema": {...}}}: the answer matches your JSON schema. name has 1 to 64 letters, digits, underscores or hyphens, and schema is a JSON schema object of at most 32 KiB. description, up to 1,024 characters, and strict, true or false, are accepted too.
  • {"type": "text"}: plain text, as without the field.
json
{
  "model": "your-model-name",
  "messages": [{"role": "user", "content": "Where is the Eiffel Tower? Answer in JSON."}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "place",
      "schema": {
        "type": "object",
        "properties": {"city": {"type": "string"}, "country": {"type": "string"}},
        "required": ["city", "country"]
      }
    }
  }
}

Any other shape, or another field inside it, gets 400 invalid_request with a message that says what is allowed. An answer that reaches max_tokens or the end of the model's context stops where it is, so its JSON can be incomplete: check that finish_reason is stop.

Images

A published vision model reads images in user messages. Send each image as an image_url part:

json
{"role": "user", "content": [
  {"type": "image_url", "image_url": {"url": "https://example.com/chart.png"}},
  {"type": "text", "text": "What does this chart show?"}
]}
  • A link is a public https:// address that answers with the image. See Image links.
  • Inline data is a base64 data URL, such as data:image/png;base64,..., with the file's real type: image/png, image/jpeg, image/webp or image/gif (image/jpg is refused). Use standard base64 with its = padding and no line breaks.
  • At most 4 images per request, counting every message.
  • detail inside image_url is accepted as a string and ignored.

Images are not stored. Each image uses tokens of the context length: see Images and the context length. A text model refuses images with 400 model_text_only. Images are on every organization. A plan Tensorant set up for your organization may leave them out: then they are refused with 403 plan_upgrade_required, and text to the same model is answered.

Tensorant downloads each linked image before the request reaches the model, and sends it inline: the model's GPU never fetches links.

A link is https:// on the standard port, with a host name: not an IP address or a .local or .internal name. It has at most 2,048 characters of plain ASCII, with no spaces, no # part and no user name or password. A query string, such as a signed link's, is fine. Any other link gets 400 invalid_request.

The host must be on the public internet and answer directly, without a redirect, with a Content-Type of image/png, image/jpeg, image/webp or image/gif, uncompressed and not empty. All of a request's links must download within 30 seconds together; a connection or read that stalls for 10 seconds fails. A link that fails here, or whose image makes the request too large (see Request size), gets 400 invalid_image.

Request size

Model Largest request
Text model 2 MiB
Vision model 20 MiB, with linked images counted base64-encoded

Base64 makes an image about a third larger, so a request holds about 15 MB of images in all, inline or linked.

Every request with images, and every request over 2 MiB, takes one of your organization's 2 places for large requests until the model answers; the API has 8 in all. More get 429 rate_limit_exceeded, "The API is busy with large requests. Try again in a moment.", with Retry-After: 1.

Send an image with Python

python
import base64
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.tensorant.io/v1", api_key=os.environ["TENSORANT_API_KEY"])

with open("receipt.jpg", "rb") as file:
    image = base64.b64encode(file.read()).decode()

answer = client.chat.completions.create(
    model="your-model-name",
    messages=[{
        "role": "user",
        "content": [
            {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image}"}},
            {"type": "text", "text": "What is the total on this receipt?"},
        ],
    }],
    max_tokens=300,
)
print(answer.choices[0].message.content)

For a link, put the https:// address in url instead.

The response

json
{
  "id": "chatcmpl-8f2c1a9e4b7d40a1",
  "object": "chat.completion",
  "created": 1791158400,
  "model": "your-model-name",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "A LoRA adapter is a small set of weights trained on top of a base model."},
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 31, "completion_tokens": 17, "total_tokens": 48}
}
  • model is the published name you sent.
  • choices holds one choice. finish_reason is stop, or length when the answer reached max_tokens or the end of the model's context.
  • usage holds the token counts, or null if the model reported none.
  • logprobs is always null. The response keeps the fields shown above; model-specific fields such as separate reasoning text or tool calls are not returned. reasoning_effort controls supported models' behavior, but does not add a reasoning field to the response.

Streaming

With "stream": true, the answer comes as server-sent events. Each event is data: and a JSON chunk; the last is data: [DONE].

text
data: {"id":"chatcmpl-8f2c1a9e4b7d40a1","object":"chat.completion.chunk","created":1791158400,"model":"your-model-name","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-8f2c1a9e4b7d40a1","object":"chat.completion.chunk","created":1791158400,"model":"your-model-name","choices":[{"index":0,"delta":{"content":"A LoRA adapter is a small set of weights."},"logprobs":null,"finish_reason":"stop"}]}

data: [DONE]
  • Each chunk's delta.content holds the next piece of the answer.
  • With "stream_options": {"include_usage": true}, one more chunk comes before [DONE], with empty choices and the usage.
  • Errors found before the answer starts come as normal JSON errors.
  • A stream that stops without data: [DONE] is incomplete: it hit a limit or the model failed. Its last event is an error in the same shape as other errors, such as data: {"error": {"message": "The answer reached its time limit", "type": "api_error", "code": "time_limit"}}, and the response ends without its final chunk, so HTTP clients report it as cut off. Retry it, or shorten the answer.

List models

bash
curl https://api.tensorant.io/v1/models -H "Authorization: Bearer $TENSORANT_API_KEY"
json
{"object": "list", "data": [{"id": "your-model-name", "object": "model", "created": 1791158400, "owned_by": "organization"}]}

data lists every published model the key may call, stopped ones included. created is when it was published. Listing counts toward the key's requests a minute and the organization's.

Cold starts and retries

A wake-on-request model that is asleep starts when a request arrives. The API holds your request for up to a minute while it starts. If it is still not ready, you get 503 model_starting with Retry-After: 15. A model that shows Starting answers 503 model_starting at once, with Retry-After: 30.

Answer Retry?
429 rate_limit_exceeded, 503 model_starting Yes, after the seconds in the Retry-After header.
429 quota_exceeded After Retry-After, at the start of next month (UTC), or once Tensorant raises the limit. See Plan limits.
500, 502 upstream_error, 503 model_unavailable with "…is not available right now." Yes, after a moment. For a 502, see 500, 502 and 503 first.
503 compute_unavailable with "Tensorant compute is not available right now." Yes, later: Tensorant compute is paused for the moment.
408 request_timeout Yes, if the whole body can arrive within 30 seconds.
400, 401, 403, 404, 405, 413, any other 503 model_unavailable No. Fix the request, the key, the plan or the model first.

Limits

Limit Value
Request body 2 MiB, or 20 MiB for a vision model, sent within 30 seconds
Requests with images or over 2 MiB, at once 2 per organization (8 on the whole API)
Messages 1 to 101
max_tokens 1 to 8,192 (512 when not sent)
stop 4 strings of 1 to 64 characters
JSON schema in response_format 32 KiB
Images 4 per request and about 15 MB together, for a vision model
Image links https, up to 2,048 characters, all downloaded within 30 seconds. See Image links.
Whole answer (not streamed) 2 minutes and 2 MiB
Stream 10 minutes from an always-on model, 5 minutes from a wake-on-request model
Pause in a stream 60 seconds
Stream size 8 MiB in all, 1 MiB per event
Cold start wait Up to 1 minute
Requests per key The key's Requests a minute and Requests at once. See Limits per key.
Requests at once per organization 64, across all its keys. See Plan limits. The API may also ask you to retry when it's busy.
Requests a minute per organization 2,000, across all its keys. See Plan limits.
Requests with an invalid key 20 a minute from one address
Requests and tokens a month Unlimited, unless a plan Tensorant set up for your organization limits them. See Plan limits.

A stream holds one of the key's Requests at once, and one of the organization's, until it ends.

Every request with a valid key counts toward the requests a minute, the key's and the organization's, even if it is refused later; only one refused by a requests-a-minute limit doesn't. Only requests that reach the model count toward the month, failed ones included. See Limits per key and Usage.

Errors

Every error has this shape:

json
{"error": {"message": "max_tokens must be a whole number from 1 to 8192", "type": "invalid_request_error", "code": "invalid_request"}}

Act on code. The message says what was wrong.

400 Bad request

Type invalid_request_error.

Code When What to do
invalid_json The body is not valid JSON. Send valid JSON.
invalid_request A field is missing or out of range, or a message, an image part or response_format is malformed. The message says what is allowed. Fix the field. See Fields, Messages, Response format and Images.
unsupported_parameter A field the API does not take. Remove it. See Fields that are refused.
invalid_image "Image URL must serve a bounded PNG, JPEG, WebP or GIF from a public HTTPS host without redirects": a linked image could not be downloaded, or made the request too large. Check the link against Image links, or send the image inline.
model_text_only Images sent to a text model. Send images only to a vision model.
model_refused The model refused the request, usually because the conversation, or max_tokens on its own, is longer than its context length. The message gives the model's reason. Shorten the conversation or lower max_tokens. If the message says to stop and start the model, an owner does so on the Models page.

401, 403, 404, 405, 408 and 413

Status Code What to do
401 invalid_api_key Send Authorization: Bearer with an active key.
403 plan_upgrade_required "Images and vision training aren't part of your organization's plan. …" A plan Tensorant set up for your organization leaves images out. Send text only, or write to [email protected]. See Images, RL and decision models. Type permission_error.
404 model_not_found The model does not exist, or the key may not call it. Check the name with GET /v1/models.
404 not_found Use /v1/chat/completions or /v1/models.
405 method_not_allowed Use POST for chat completions and GET for models.
408 request_timeout Send the whole body within 30 seconds.
413 request_too_large Over 2 MiB to a text model: shorten the conversation. Over 20 MiB: send fewer or smaller images.

429 Too many requests

Each has a Retry-After header with the seconds to wait.

Code Message Meaning
rate_limit_exceeded "This key sent too many requests. Slow down." The key reached its Requests a minute.
rate_limit_exceeded "This organization sent too many requests this minute. Its plan (Plan) allows N a minute. …" Your organization reached its requests a minute, across all its keys. Wait the Retry-After seconds.
rate_limit_exceeded "This key has too many requests in flight" The key reached its Requests at once.
rate_limit_exceeded "This organization has N requests in flight, as many as its plan (Plan) allows. …" Your organization reached its requests at once, across all its keys. Retry after a moment.
rate_limit_exceeded "The API is busy. Try again in a moment." The API is at capacity. Retry after a moment.
rate_limit_exceeded "The API is busy with large requests. Try again in a moment." Too many requests with images or over 2 MiB at once. See Request size.
rate_limit_exceeded "Too many requests with an invalid API key. Wait a minute." Your address sent 20 requests with an invalid key in a minute. For a minute, all its requests are refused, even with a valid key.
quota_exceeded "This organization used the API requests a month its plan (Plan) allows. …" A plan Tensorant set up for your organization limits API requests a month, and they are used up. Retry-After runs to the start of next month (UTC). See Plan limits.
quota_exceeded "This request's full context window does not fit the API tokens a month its plan (Plan) allows. …" What is left of the plan's API tokens a month is less than the model's context window, which every request reserves.

The type is insufficient_quota for quota_exceeded and rate_limit_error for the others.

500, 502 and 503

Status Code Message What to do
500 internal_error "The request could not be handled" Try again. If it keeps happening, contact support.
502 upstream_error "The model did not answer in time" The answer took over 2 minutes. Lower max_tokens, or stream.
502 upstream_error "The model's answer was too large" Lower max_tokens.
502 upstream_error Other messages The model failed this time. Try again.
503 model_starting "The model 'name' is starting. Try again shortly." Wait the Retry-After seconds and send it again.
503 model_unavailable "The model 'name' is stopped. Start it on the Models page of the console." An owner starts the model on the Models page.
503 model_unavailable "The model 'name' reached its end date on YYYY-MM-DD. Start it again on the Models page of the console." The always-on model reached its end. An owner starts it again on the Models page, and extends it before its next end.
503 model_unavailable "The model 'name' could not be started. See the Models page of the console." See When a start fails.
503 model_unavailable "The model 'name' could not be loaded by its server. See the Models page of the console." Its server is up but could not load this model's adapter, so sending it again won't help. The serving logs say why: see When a start fails.
503 model_unavailable "The model 'name' is not available right now." Try again in a moment.

The type is api_error for 500 and 502, and service_unavailable for 503.

Need a hand? Visit troubleshooting