putty
API ReferenceInference

Create a chat completion (OpenAI-compatible)

OpenAI-compatible chat completion endpoint. Accepts the same body shape as OpenAI's `POST /v1/chat/completions` and returns the same response shape, either a JSON `ChatCompletion` (when `stream: false`, the default) or a `text/event-stream` of `ChatCompletionChunk` objects (when `stream: true`). The bearer token is either a Privy access token (the dashboard) or an `sk-` API key (services). Threads are persisted via a custom header — see the Inference module docs for the full list of non-OpenAI headers. When the upstream provider fails, a `stream: false` call returns 502 with the provider's message, and a streamed call ends with a chunk that carries an `error` object (`{ message }`) before `data: [DONE]`. A streamed call never ends without either a `finish_reason` or that error chunk. For a client-side tool loop, send every earlier `tool_calls` entry together with its `role: "tool"` result: an unmatched tool call is a request the upstream cannot serve.

POST
/v1/chat/completions

OpenAI-compatible chat completion endpoint. Accepts the same body shape as OpenAI's POST /v1/chat/completions and returns the same response shape, either a JSON ChatCompletion (when stream: false, the default) or a text/event-stream of ChatCompletionChunk objects (when stream: true). The bearer token is either a Privy access token (the dashboard) or an sk- API key (services). Threads are persisted via a custom header — see the Inference module docs for the full list of non-OpenAI headers. When the upstream provider fails, a stream: false call returns 502 with the provider's message, and a streamed call ends with a chunk that carries an error object ({ message }) before data: [DONE]. A streamed call never ends without either a finish_reason or that error chunk. For a client-side tool loop, send every earlier tool_calls entry together with its role: "tool" result: an unmatched tool call is a request the upstream cannot serve.

Authorization

bearerAuth
AuthorizationBearer <token>

A bearer token. The Account routes accept a Privy access token; the MCP transport accepts an sk- API key issued by POST /account/api-keys.

In: header

Request Body

application/json

The OpenAI Chat Completions request body.

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/v1/chat/completions" \  -H "Content-Type: application/json" \  -d '{    "model": "string",    "messages": [      {        "role": "system",        "content": "string"      }    ]  }'
{  "id": "string",  "object": "chat.completion",  "created": 0,  "model": "string",  "choices": [    null  ],  "usage": null}