---
title: "Chat completion, paid per call via x402"
method: POST
path: "/v1/chat/completions"
---

# Chat completion, paid per call via x402

`POST /v1/chat/completions`

## Request

- Base URL: `https://agents.dexl.io`
- URL: `https://agents.dexl.io/v1/chat/completions`
- Auth: API key in header `X-Payment`

Send without payment to receive a 402 carrying the exact price, then sign and resend.

## Request body

- object
  - `model` string, required
  - `messages` object[], required
    - `role` 'system' | 'user' | 'assistant', required
    - `content` string, required
  - `max_tokens` integer: Output ceiling. The quote is computed against this, so it cannot be unlimited.
  - `temperature` number

## Response `200`

Payment settled, completion returned

- object
  - `id` string, required: Request id, also returned as X-DexL-Request-Id
  - `object` string
  - `created` integer
  - `model` string, required
  - `choices` object[], required
    - `index` integer
    - `message` object
      - `role` string
      - `content` string
    - `finish_reason` string
  - `usage` object, required
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer

## Other responses

- `402`: Payment required - exact price in the PAYMENT-REQUIRED header
- `404`: Model not found - no payment was taken
- `405`: Method not allowed - this endpoint is POST only
- `429`: Rate limited - Retry-After says when

---

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