Gateway
Connect apps to Nexus through OpenAI-compatible and Anthropic-compatible APIs
The Nexus gateway gives local clients one API surface for local and online models. Clients authenticate to Nexus with a local Nexus token; Nexus resolves the model, reads provider credentials from secure storage when needed, and forwards only safe provider hints upstream.
Base URL and authentication
Copy the gateway URL from the app. The default production listener is local-only:
Accepted token forms:
Use x-api-key for Anthropic-compatible clients that expect that header. It is still a local Nexus token and is never forwarded to the upstream provider.
Supported gateway routes
Nexus routes requests by model and endpoint family.
OpenAI-compatible routes include:
GET /v1/modelsPOST /v1/chat/completionsPOST /v1/embeddingsPOST /v1/responsesPOST /v1/responses/input_tokensPOST /v1/responses/compactGET /v1/responses/{id}DELETE /v1/responses/{id}GET /v1/responses/{id}/input_itemsPOST /v1/responses/{id}/cancelPOST /v1/images/generationsPOST /v1/images/editsPOST /v1/audio/speechPOST /v1/audio/transcriptions
Anthropic-compatible routes include:
POST /v1/messagesPOST /v1/messages/count_tokens
Rerank routes include:
POST /v1/rerank
Not every provider or model supports every route. Check API and SDKs or GET /v1/capabilities for the current machine-readable contract.
Endpoint families
Model records advertise endpoint-family IDs:
openai.chat_completionsopenai.embeddingsopenai.responsesopenai.imagesopenai.audio_speechopenai.audio_transcriptionsanthropic.messagesrerank.documents
Nexus validates the family before provider credential lookup. If a model lacks the required family, the request fails locally instead of reaching the provider.
Model values
Gateway requests can target:
- Direct model IDs such as
openai/gpt-test,ollama/llama3.1:8b, orllamacpp/qwen.gguf - Aliases such as
default-chat - Presets such as
@preset/coder-fast - Route packs such as
@route/research
Direct model IDs take precedence over aliases. Hidden models are omitted from /v1/models and cannot be routed by direct ID or alias.
Multipart routes, including image edits and audio transcriptions, accept model IDs or aliases only. They do not accept presets or route packs because Nexus must resolve the multipart model field before streaming the upload onward.
Provider resolution
Nexus resolves requests in this order:
- Identify the model, alias, preset, or route pack.
- Validate the selected endpoint family.
- Resolve the provider record and provider kind.
- Merge preset defaults when a preset is used.
- Apply request fields last.
- Send the upstream request with the credential stored inside Runtime.
Preset params and provider-specific options act as defaults. A request body can override those values for one call.
Header boundary
Clients must not send upstream provider credentials to Nexus. Nexus ignores or blocks protected transport headers and sets provider authentication itself.
Allowed provider hints include non-secret headers for use cases like:
- OpenAI project or organization selection
- Anthropic beta feature headers
- OpenRouter referer, title, category, or experimental metadata
Nexus strips hop-by-hop headers, credential-bearing response headers, and provider CORS headers before responses reach clients.
Image, audio, and rerank behavior
Newer gateway routes follow the same local-token and model-family rules as text routes:
- Image generation uses JSON, can be routed by model, alias, preset, or route pack, and records provider-reported token counters when the provider returns them.
- Image edits use
multipart/form-data, require onemodelfield pluspromptandimageorimage[]file parts, and are direct-model-or-alias only. - Speech accepts JSON text-to-speech requests and relays the provider's binary audio response byte-for-byte.
- Transcriptions accept multipart audio uploads or JSON
input_audio, depending on provider support, and are direct-model-or-alias only for multipart requests. - Rerank uses a vendor-neutral
{ model, query, documents[] }shape and returns indexed relevance scores.
Audio speech, audio transcription, image edit, and rerank requests are not token-metered in Usage today. Image generation records token counters only when the provider reports them.
Request IDs and errors
Every response includes a Nexus request ID:
X-Msty-Nexus-Request-IdX-Request-Idrequest-id
Errors use stable machine-readable codes:
Branch on error.code, not on English message.
Browser clients and CORS
CORS is disabled by default. Add explicit browser origins in Settings > Network Access before calling Nexus from a browser page.
Important boundaries:
- Preflight requests for allowed origins do not need a token.
- Actual
/v1/*requests always need a token. *is development-only and must be the only CORS entry when used.- CORS does not change the bind address.
If a browser client fails before it reaches the API, check the CORS allow-list first. If a request reaches the API and returns UNAUTHORIZED, check the local Nexus token.