# Chat completions

`POST https://api.openmayhem.ai/v1/chat/completions`, shaped like OpenAI's.
`POST https://api.openmayhem.ai/v1/completions` and `POST https://api.openmayhem.ai/v1/responses` exist for the
same models; `/responses` is stateless by design.
`POST https://api.openmayhem.ai/v1/embeddings` serves embedding models with the same auth and
billing.

```bash
curl https://api.openmayhem.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENMAYHEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "prism-ml/ternary-bonsai-27b",
    "messages": [{"role": "user", "content": "Explain signed receipts."}],
    "max_tokens": 2000,
    "temperature": 0.7
  }'
```

## Parameters

Everything beyond the required fields passes through to the network, which
validates it against the model's signed request contract. An unsupported
attribute is rejected with 400 before any provider runs, so it costs
nothing. Each model's catalog entry (`GET https://api.openmayhem.ai/v1/models/{id}`) lists its
supported parameters and request contracts.

Reasoning models think before they answer, and thinking consumes
`max_tokens`. Budget 2000 tokens or more.

## Idempotency

Send an `Idempotency-Key` header to make retries safe: the same key
returns the original request's result instead of running and billing twice.

## Cost lookup

`GET https://api.openmayhem.ai/v1/requests/{id}` (CHAT scope) returns a request's settled
usage, cost and receipt after the fact. The request id arrives in the
response body as `openmayhem.request_id` (streaming responses also carry
an `x-request-id` header).
