Skip to Content
Chat completions

Chat completions

POST /v1/chat/completions — the OpenAI Chat Completions format for OpenAI SDKs and tools.

POST https://api.strokes.ink/v1/chat/completions

The same models, prices and billing as /v1/messages, in OpenAI's Chat Completions format. Use it when your code or framework already speaks OpenAI: point the OpenAI SDK at https://api.strokes.ink/v1 with your Strokes key.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.STROKES_API_KEY,
  baseURL: "https://api.strokes.ink/v1",
});

const completion = await client.chat.completions.create({
  model: "swim-1.0",
  messages: [
    { role: "system", content: "You are a careful editor." },
    {
      role: "user",
      content: "Tighten this sentence: In order to be able to win, we need to try.",
    },
  ],
});
console.log(completion.choices[0].message.content);

Request

FieldType
modelstringRequired. swim-1.0. See Models
messagesarrayRequired. Messages with the roles system, developer, user, assistant and tool. user content is a string or text and image_url parts; images are a URL or a data: URL
max_completion_tokensintegerThe most tokens to write. max_tokens is accepted too. Defaults to the model's maximum
streambooleanStream the reply as server-sent events
stream_options.include_usagebooleanSend a last chunk with usage before [DONE]
stroke_idstringThe stroke the request belongs to. The stroke-id header works too
modestringThe kind of writing: business, academic or creative. Left out, the API picks one for the request. See Modes
toolsarrayFunction tools: {"type": "function", "function": {"name", "description", "parameters"}}
tool_choicestring or objectnone, auto, required or {"type": "function", "function": {"name": …}}
parallel_tool_callsbooleanfalse asks for at most one tool call per reply
temperaturenumberFrom 0 to 1
top_pnumberFrom 0 to 1
stopstring or arrayUp to 4 sequences that end the reply
web_searchbooleanWhether the model may search the web and read pages, as in Web search. Default true for swim-1.0
web_search_optionsobjectHow much the model may search: search_context_size low, medium (the default) or high — up to 3, 5 or 10 searches and reads. user_location is accepted and ignored. Not with "web_search": false
reasoning_effortstringHow much the model reasons before it writes — see reasoning

system and developer messages are joined into one system prompt wherever they are in the list. web_search, mode and stroke_id are Strokes' own fields: in the OpenAI SDKs, pass them in extra_body, such as extra_body={"web_search": False} in Python, or in the body with a // @ts-expect-error in TypeScript.

Not supported, and answered with a 400: n above 1, logprobs, and a response_format other than text. Other fields, such as user, seed and the penalties, are accepted and ignored.

Reasoning

reasoning_effort
left out, minimal or lowLittle or no reasoning. The default
medium or highSome reasoning
xhighReasons in full, often thousands of tokens
noneAs low, and the reasoning isn't returned

When the model reasoned, its reasoning comes back as message.reasoning_content (in a stream, delta.reasoning_content), unless reasoning_effort is none. Reasoning tokens are part of completion_tokens and billed. An assistant message in the history that carries only reasoning_content is skipped: the model never sees its earlier reasoning.

Response

{
  "id": "chatcmpl-oy7P0NNEFhLHJpJhxqLzTeVT",
  "object": "chat.completion",
  "created": 1795600000,
  "model": "swim-1.0",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "To win, we need to try.",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 38,
    "completion_tokens": 21,
    "total_tokens": 59,
    "prompt_tokens_details": { "cached_tokens": 0 }
  }
}

A reply that calls tools has message.tool_calls and finish_reason tool_calls; send each result back as a tool message with its tool_call_id. finish_reason is length when max_completion_tokens cut the reply short.

Unless web_search is false, the model decides whether to search, with or without web_search_options. The pages it read are in message.annotations as url_citation entries with each page's url and title; they cite the whole answer, so start_index and end_index are both the answer's length. Each search and page read is billed as in Web search.

usage counts every round of the reply, its web searches included, as on /v1/messages. prompt_tokens is all input; prompt_tokens_details.cached_tokens is the part read from the prompt cache.

Streaming

With stream: true the reply comes as chat.completion.chunk events, each a data: line, and ends with data: [DONE]. Reasoning streams as delta.reasoning_content before the answer's delta.content. Tool calls stream as delta.tool_calls with their arguments in pieces. With web search, the sources come in one chunk's delta.annotations before the last chunk. While the model searches, the stream sends : ping comments to keep the connection open.

Errors

Errors have OpenAI's shape and the same status codes as /v1/messages:

{
  "error": {
    "message": "model: strokes-large",
    "type": "not_found_error",
    "param": null,
    "code": null
  }
}

Every response carries a request-id header.

On this page