Core

Chat completions

The OpenAI chat completions endpoint for Claude, GPT and Gemini. The parameters that it accepts, the response, images, and the parameters that it refuses.

POST /v1/chat/completions

The request and the response have the OpenAI format. We do not change the field names, so an OpenAI client works without a change. Claude, GPT and Gemini models work on this endpoint. See Supported endpoints.

Parameters

FieldNotes
modelNecessary. A model id. See Models
messagesNecessary. Roles system, user, assistant and tool. content is a string, or a list of parts for images
max_tokensThe maximum number of output tokens. The default is 16,000 (4,096 on the starter balance) and the maximum is 128,000. Without max_tokens, a low balance lowers the default to what the balance can hold, but never below 1,024. We hold the cost of this number of tokens from your balance until the request completes
max_completion_tokensThe newer OpenAI name for max_tokens. Send one of the two. If you send the two with different values, you get a 400 error
temperature, top_p, stop, seedWe send them to the model. The ranges are the OpenAI ranges
frequency_penalty, presence_penaltyWe send them to the model
stream, stream_optionsSee Streams
tools, tool_choice, parallel_tool_callsSee Tool calls
response_formatSee Structured output
reasoning_effort, verbosityWe send them to the model. See Models
logprobs, top_logprobsWe send them to the model
prompt_cache_keySee Prompt cache

The response

{
  "id": "chatcmpl-8f2a1c",
  "object": "chat.completion",
  "created": 1791331200,
  "model": "claude-haiku-4-5-20251001",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "The capital of Kenya is Nairobi." },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 21,
    "completion_tokens": 8,
    "total_tokens": 29,
    "prompt_tokens_details": { "cached_tokens": 0 }
  },
  "kontinent": { "request_id": "req_8f2a1c", "cost_micros": 13, "cost_usd": 0.000013, "list_price_usd": 0.000061, "saved_usd": 0.000048 }
}

The kontinent block is not part of the OpenAI format. An OpenAI client ignores it. It shows the cost of the request, the cost at the official price, and the difference. See Supported endpoints.

finish_reason comes from the model:

ValueMeaning
stopThe model completed its answer
lengthThe model used all of max_tokens
tool_callsThe model asks you to run a function
errorThe stream stopped after it started. See Reliability

Conversations

Send all of the conversation in each request. We keep no state between requests.

messages = [{"role": "system", "content": "Answer in one sentence."}]

while True:
    messages.append({"role": "user", "content": input("> ")})
    reply = client.chat.completions.create(model="claude-haiku-4-5-20251001", messages=messages)
    text = reply.choices[0].message.content
    messages.append({"role": "assistant", "content": text})
    print(text)

Images

Some models can read images. To send an image, make content a list of parts, as in the OpenAI format:

{
  "model": "claude-sonnet-5-5",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "What is in this picture?" },
        { "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
      ]
    }
  ]
}

Before you send an image, look at input_modalities in GET /v1/models. A model that reads images shows ["text", "image"]. If you send an image to a model that shows only ["text"], you get a 400 error that names messages. We do not charge for that request.

We charge for an image on the token count that the model gives. The usage block of the response shows that count.

What this endpoint does not do

n larger than 1 does not work. Send the request more than one time. For the other parameters and endpoints that we do not have, see Not supported yet.