---
title: "OpenAI-compatible chat completions, governed and recorded"
method: POST
path: "/v1/chat/completions"
tags: ["proxy"]
---

# OpenAI-compatible chat completions, governed and recorded

`POST /v1/chat/completions`

## Request

- Base URL: `https://www.spendline.ai`
- URL: `https://www.spendline.ai/v1/chat/completions`
- Auth: API key in header `x-spendline-key`

Set the OpenAI SDK baseURL/base_url to https://www.spendline.ai/v1. WITH /v1. The SDK appends /chat/completions itself.

Providers reachable on this shape: openai, google, xai, mistral, deepseek, qwen, together, fireworks, groq.
The model name selects the provider (gpt-* → OpenAI, gemini-* → Google, grok-* → xAI, mistral-* → Mistral, …).

Streaming is supported. Request/response bodies are the provider's own. Spendline
does not reshape them.

## Headers

- `Authorization` string, required
- `x-agent-id` string
- `x-customer-id` string
- `x-spendline-tags` string
- `x-workflow-id` string
- `x-step-name` string
- `x-source-route` string

## Request body

- object
  - `model` string, required: Selects the provider. See /agents/providers.md.
  - `messages` object[], required
  - `stream` boolean
  - `max_tokens` integer: Also used to project pre-call cost for budget enforcement. A realistic value makes enforcement more accurate.

## Response `200`

Provider response, passed through unchanged. The call is recorded in the ledger.

## Other responses

- `400`: missing_required_attribution, a required attribution header is absent while enforcement is on.
- `401`: The Spendline key is missing or invalid. Do NOT fall back to the provider.
- `402`: A budget blocked this call BEFORE any spend occurred. Intended behaviour. Surface it; never retry against the provider directly.
- `403`: A policy or governance rule blocked the call. Never route around it.
- `429`: Rate limited. Back off and retry.
- `502`: Upstream provider error, or Spendline could not reach it. This is the only class of failure where retrying directly against the provider is correct.

---

[API](https://skmtc.dev/spendline/apis/spendline-api.md) · [All operations](https://skmtc.dev/spendline/apis/spendline-api/llms.txt) · [OpenAPI document](https://skmtc.dev/spendline/apis/spendline-api/revisions/eb22b9415a28?raw)
