Skip to content
Fossa

Chat completions

Send text and tool requests and read streamed replies.

Create a completion

Replace MODEL_ID with an ID from the model list. Choose a new Idempotency-Key for each intended completion. This request streams the reply as server-sent events. Set stream to false, or omit it, for one JSON response.

Chat currently accepts text messages and supported tool calls. It does not accept image, audio, or video content. Choose a model that declares tool support before sending tools.

Use an HTTP client

Use the same bearer header and JSON body from any HTTP client. This example reads a non-streaming reply. Store FOSSA_MODEL as an exact model ID. Do not automatically retry a completion with a new request ID after a timeout.

Request compatibility

Send a JSON object with model and a nonempty messages array. Messages accept system, developer, user, assistant, and tool roles. Content accepts text or text-part arrays. Assistant messages can include reasoning_content, refusal, and function tool_calls. Tool results must refer to an earlier call ID.

FieldAccepted values
max_tokens or max_completion_tokensPositive whole number. Supply at most one of these fields.
streamBoolean; default false.
reasoning_effortA value published for the selected model.
temperature, top_pNumbers in 0–2 and 0–1, respectively. Omitted values use published model settings when available.
frequency_penalty, presence_penaltyNumbers in -2–2.
tools, tool_choice, parallel_tool_callsFunction tools for a model with tool support. Choice accepts auto, none, required, or a function selector. Parallel calls accepts a boolean.
response_formattext, json_object, or json_schema format objects. The selected model must support the requested behavior.
seed, stopA safe whole-number seed; a stop string or at most four strings.
stream_optionsBoolean include_usage and include_obfuscation fields, with stream: true.
n, store, logprobsOnly 1, false, and false, respectively. Omit these fields to use the same behavior.

The endpoint does not implement other OpenAI API families or every optional Chat Completions field. Unsupported content and fields fail before booking. The provider still determines supported generation behavior.

Read responses

Without streaming, read the provider’s JSON chat completion. choices contains its messages and finish reasons. usage, when supplied, contains token counts. With streaming, read Content-Type: text/event-stream, parse each data: JSON chunk, and stop at data: [DONE]. A dropped connection can leave a partial answer. The API forwards provider response bytes without retaining a reply for replay.

The completion response includes X-Request-Id. A submitted reservation also supplies X-Fossa-Transaction. Keep the request ID for status lookup and support. The model response and displayed usage do not establish confirmed settlement; confirmed booking state or an authenticated receipt determines the charge.