API Reference

July 8, 2026 · View on GitHub

CrossLink exposes three groups of endpoints: the gateway (OpenAI/Anthropic-compatible, API-key auth), the MCP gateway (JSON-RPC/SSE, API-key auth), and the admin API (JWT auth, used by the dashboard).

All gateway endpoints accept either an OpenAI-format or Anthropic-format request body and return the matching format. Protocol translation — including streaming SSE, tool use, and extended thinking — is handled internally.

Authentication

ScopeHeaderFormat
Gateway & MCPAuthorization: Bearer <key>API key prefixed cl- (48 hex chars)
AdminAuthorization: Bearer <jwt>JWT obtained from POST /admin/api/auth/login

API keys are stored hashed (never plaintext). The cl- prefix lets clients fail fast on malformed keys.


Gateway endpoints

POST /v1/chat/completions

OpenAI-compatible chat completions. Supports both streaming ("stream": true) and non-streaming.

curl http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer cl-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "stream": true,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

POST /v1/messages

Anthropic-compatible messages. Same routing and failover behavior as the OpenAI endpoint; the request and response are translated to/from Anthropic format.

curl http://localhost:8080/v1/messages \
  -H "Authorization: Bearer cl-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

GET /v1/models

Lists the models available to the calling key (filtered by RBAC).


Response headers

Every gateway response carries headers that make routing behavior observable:

HeaderWhen setMeaning
x-crosslink-fallback-modelAlways (when a model is determined)The model that actually served the request. Differs from the requested model when a cross-model fallback occurred.
x-crosslink-fallback-countOnly when at least one fallback happenedNumber of providers attempted before success.

Inspecting these lets you verify failover in real time — for example, logging them alongside latency to detect providers that are quietly degrading.

Stream interruption

If an upstream SSE stream ends without a terminal [DONE] (network blip, upstream crash), CrossLink emits a structured error event instead of silently truncating:

data: {"error":{"type":"stream_interrupted","message":"upstream stream ended unexpectedly"}}

Clients get a machine-readable signal that the stream was incomplete, so they can retry rather than treating partial output as final.

Error responses

Errors are returned in the format matching the request (OpenAI-style for /v1/chat/completions, Anthropic-style for /v1/messages). Common HTTP status codes:

StatusMeaning
400Malformed request body
401Missing or invalid API key
403RBAC denied (key lacks access to model/provider/MCP tool)
429Rate limit (RPM/TPM) or concurrency limit hit
502All providers in the fallback chain failed
503Gateway is draining (during graceful shutdown)

MCP gateway endpoints

POST /mcp/:server

Forwards a JSON-RPC request to the named MCP server. Tool calls are subject to per-principal RBAC (see MCP Gateway).

GET /mcp/:server

SSE transport for the named MCP server.


Admin endpoints

All admin endpoints require a JWT. The dashboard obtains it via login and refreshes it automatically.

MethodPathDescription
POST/admin/api/auth/loginLogin, returns JWT
CRUD/admin/api/providersProvider management (test connectivity via POST /:id/test)
CRUD/admin/api/modelsModel mapping management
CRUD/admin/api/keysAPI key management (regenerate via POST /:id/regenerate)
GET/admin/api/usageUsage logs with multi-dimensional filtering
GET/admin/api/usage/statsUsage statistics
GET/admin/api/usage/dailyDaily usage trends
GET/admin/api/routing/statsRouting distribution: configured vs. actual weight per provider, deviation, error rate, latency, tokens, cost (see Routing & Failover)
CRUD/admin/api/mcp/serversMCP server management
GET/admin/api/mcp/servers/:id/toolsList tools on an MCP server

The full admin surface is larger than what the dashboard exposes. Explore the route registrations in internal/app/app.go for the complete list.