---
title: "OpenAI Chat Completions"
method: POST
path: "/v1/chat/completions"
---

# OpenAI Chat Completions

`POST /v1/chat/completions`

## Request

- Base URL: `https://api.agentlab.cresclab.com`
- URL: `https://api.agentlab.cresclab.com/v1/chat/completions`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/cresclab/apis/agent-lab-ai-gateway/docs/v1/chat/completions/post.ts> (a function with typed inputs; its response is checked against the schema)

Any model the workspace allows. model is auto or a name from GET /v1/models; the response names the model that answered and adds agentlab_decision.

## Headers

- `X-AgentLab-Routing` 'auto' | 'auto:cost' | 'auto:balanced' | 'auto:quality'
- `Idempotency-Key` string

## Request body

- ChatCompletionRequest
  - `model` string, required: auto, auto:cost, auto:quality or a name from GET /v1/models.
  - `messages` object[], required
  - `tools` unknown[]
    - unknown
  - `max_completion_tokens` integer
  - `max_tokens` integer
  - `stream` boolean
  - `stream_options` object
    - `include_usage` boolean
  - `response_format` object
  - `user` string: Recorded as the request's end user.
  - `agentlab` object
    - `schema_version` unknown
    - `tool_calling` boolean
    - `vision` boolean
    - `structured_output` boolean
    - `minimum_context_tokens` integer

## Response `200`

The model's answer, or a text/event-stream when stream is true.

- object

## Other responses

- `400`: Refused request. See the error catalog.
- `401`: Missing or not accepted key.
- `403`: Not allowed for this key or workspace.
- `429`: Rate limited or out of allowance. Retry-After and X-Should-Retry say whether to retry.
- `502`: The provider failed to answer.
- `503`: Gateway unavailable or settlement pending.

---

[API](https://skmtc.dev/cresclab/apis/agent-lab-ai-gateway.md) - [All operations](https://skmtc.dev/cresclab/apis/agent-lab-ai-gateway/llms.txt) - [OpenAPI document](https://skmtc.dev/cresclab/apis/agent-lab-ai-gateway/revisions/5dc08011cbe9?raw)
