Chat Completions

POST /v1/chat/completions, the OpenAI wire format across every text and code model, with streaming and exact usage. POST /v1/responses serves OpenAI's Responses API on the same models.

Endpoint

Standard OpenAI request and response shapes, messages in, choices out. Existing OpenAI SDK code works unchanged after swapping the base URL and key.

POST https://api.companyfabric.com/v1/chat/completions

Streaming

Set stream: true for server-sent events. Delta chunks arrive in the OpenAI format. With stream_options: { include_usage: true }, a last chunk before [DONE] carries the usage object including cost_usd, what the request charged: read it to reconcile spend without a second request. It has an empty choices array, so guard for that as below.

const completion = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5-5",
  messages: [{ role: "user", content: "Stream me." }],
  stream: true,
  stream_options: { include_usage: true },
})
for await (const chunk of completion) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "")
  if (chunk.usage) console.error("cost:", chunk.usage.cost_usd)
}

Request tracing

Every response carries an x-fabric-request-id header. Include it when reporting an issue, it links your request to the exact ledger row and upstream trace.

Responses API

POST /v1/responses accepts OpenAI's Responses API: input in, output items out. Use it when your code calls client.responses.create, or the Vercel AI SDK's openai(model), which uses the Responses API by default. Same key, same models, same per-token billing as /v1/chat/completions, and usage.cost_usd carries what the request charged.

Supported: instructions, text and image input, input_file with file_data, function tools with tool_choice and parallel_tool_calls, function_call_output, max_output_tokens, reasoning.effort, text.format (json_schema and json_object), and stream: true, which sends the standard Responses events from response.created to response.completed.

const response = await client.responses.create({
  model: "companyfabric/auto",
  instructions: "You are a concise assistant.",
  input: "Say hello.",
})
console.log(response.output_text)

Responses API: stateless

CompanyFabric does not store responses, so send the whole conversation in input on every request. Requests that depend on stored state are refused with a 400 whose resolution says what to send instead, rather than answered without that context.

  • previous_response_id and conversation: send the earlier turns in input.
  • background: remove it, and use stream: true for long answers.
  • Stored prompt templates (prompt): send instructions and input directly.
  • item_reference to anything other than a reasoning item: send the item itself. In the Vercel AI SDK, set providerOptions.openai.store = false as above.
  • file_id and file_url: send images as image_url (an https or data: URL) and files as file_data.
  • OpenAI's hosted tools (web_search, file_search, code_interpreter and the rest) run on OpenAI's side and are not available: define the capability as your own function tool.