OP Inference

Chat completions

Send messages to a text model and get a reply.

POST /v1/chat/completions takes the OpenAI chat completions request and returns the OpenAI response shape. Existing OpenAI code works by pointing it at https://api.opinference.com/v1.

curl https://api.opinference.com/v1/chat/completions \
  -H "Authorization: Bearer $OP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-oss-120b",
    "messages": [
      {"role": "system", "content": "Answer in one sentence."},
      {"role": "user", "content": "What is a gateway?"}
    ],
    "max_completion_tokens": 200
  }'

Request

FieldNotes
modelRequired. A model id from GET /v1/models
messagesRequired. content is a string or an array of content parts
streamtrue streams the reply. See Streaming
max_completion_tokensUpper bound on output tokens. max_tokens is read too; when both are sent the larger wins. Reasoning models count their reasoning against it, so a small cap can leave no answer, which fails the request
temperaturePassed to the model
tools, tool_choiceSee Tool calling
response_formatSee Structured output
modelsOther models that may answer. See Fallbacks
providerRouting preferences. See Provider preferences
opRetention, tags and session. See Data retention
pluginsNot supported. A non-empty plugins (web search, file parsing) is refused with 400 invalid_request and param: "plugins" rather than ignored. For web search, run a search tool and pass its results in messages

Other fields this table does not list are ignored.

The request is routed only to endpoints that support what it asks for. A request with tools goes only to endpoints that support tool calling, and a request whose prompt and output limit do not fit an endpoint's context window is not sent there.

Images, PDFs and video

A message's content may be an array of parts. Four part types are accepted:

typeFormLimitsThe model must accept
text{"text": "..."}The 25 MiB request bodyAny model
image_url{"image_url": {"url": "..."}}, an https URL or an image data: URIThe 25 MiB request bodyImages
file{"file": {"filename": "cv.pdf", "file_data": "data:application/pdf;base64,..."}}10 MiB per PDF, 16 MiB of PDFs per request, 5 per requestPDFs
video_url{"video_url": {"url": "https://..."}}1 per requestVideo
{
  "model": "google/gemini-3-flash-preview",
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "List the job titles in this CV."},
      {"type": "file", "file": {"filename": "cv.pdf", "file_data": "data:application/pdf;base64,JVBERi0x..."}}
    ]
  }]
}
  • A file part is a PDF sent inline as base64. Its decoded bytes must begin %PDF-. file_id, file_url and other file types are refused.
  • A video_url must be an https URL with a host name and no user name or password in it.
  • A part we do not accept is refused with 400 invalid_request, and param names it, for example messages[0].content[1]. We never drop a part and send the rest. Over a size limit is 413 payload_too_large; over a count limit is 400 invalid_request.
  • A request with a PDF goes only to endpoints that have passed our PDF check, and a request with a video only to those that have passed our video check. A model listing PDFs or video as an input is not enough, because some endpoints answer while ignoring the part. With no such endpoint the answer is 404 no_endpoint_available and no provider is called.
  • Before routing, a PDF counts as 10,000 input tokens and a video as 25,000 against an endpoint's context window. These are estimates. Your budget reserves up to the endpoint's full context for such a request. You are billed for the input tokens the provider reports, which can be far fewer or far more for the same PDF.
  • If you turn on request logging, the log keeps each PDF and video part as its size and SHA-256 only, never the PDF or the URL.

Response

{
  "id": "gen_...",
  "object": "chat.completion",
  "created": 1790940214,
  "model": "openai/gpt-oss-120b",
  "provider": "nebius",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A gateway is a single entry point that forwards requests to other services."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 72,
    "completion_tokens": 18,
    "total_tokens": 90
  }
}
  • id is the generation id. It also arrives in the x-op-generation-id header and is the id shown on your usage and request pages.
  • model is the model that answered. Without models it is always the model you asked for.
  • provider is the id of the provider that answered, the same id as on GET /v1/models/{id}/endpoints. Every stream chunk carries it too.
  • A reasoning model may add message.reasoning and report usage.completion_tokens_details.reasoning_tokens. Reasoning tokens are output tokens and are billed as such.
  • usage.prompt_tokens_details.cached_tokens, when present, counts input tokens served from a prompt cache.

Retrying safely

Send an Idempotency-Key header to make a retry safe. A chat completion is not replayed: a repeat of a key that is in progress or finished returns 409 idempotency_conflict instead of running and billing a second time. See Idempotency. Request ids and the op_metadata receipt are on Request ids and metadata.

Errors

A failed request returns an HTTP error with a JSON envelope:

{
  "error": {
    "code": "no_endpoint_available",
    "message": "no endpoint serves model \"no-such/model\"",
    "kind": "terminal",
    "scope": "model",
    "type": "invalid_request_error",
    "param": null,
    "request_id": "req_..."
  }
}

Switch on code. See Errors for every code and which ones are worth retrying.