Chat Completions

POST /v1/chat/completions, the OpenAI wire format across every text and code model, with streaming and exact usage.

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.