Chat Completions
POST/gateway/v1/chat/completions
OpenAI-compatible Chat Completions through a gateway router. Set model to the router's name: the router picks one of its models, Emissary calls it with the router's provider key, and returns the provider's answer in Chat Completions format. The response's model is the id of the model that served it. With stream: true the answer streams as server-sent events, as OpenAI streams them. If the picked model's provider fails, the router's default model serves instead.
With the OpenAI SDK, set the base URL to https://api.withemissary.com/gateway/v1 and the API key to your Emissary API key. The gateway takes the key in X-API-Key or as a bearer token (Authorization: Bearer <key>), which is how the OpenAI SDK sends it.
Routing is cache-aware within a session: a session id in an x-session-id header, or in the headers Claude Code, Codex and other known clients send, keeps a conversation's later turns on the model whose prompt cache is warm.
Request
Responses
- 200
- 400
- 401
- 402
- 403
- 404
- 504
- default
The provider's answer, in Chat Completions format
The request can't be served as sent, for example because its body isn't a JSON object or model names a Proposal Mode router
Unauthorized error
Your prepaid credits are exhausted
The API key is not valid
None of your routers has the name in model
The model's provider didn't respond
An error from the model's provider, passed through with its status and body