Reference

LLM Gateway

Point any app that speaks the Anthropic Messages API at DirectOS — and get routing, fallbacks, budgets and a log line for every call.


What you get

  • Drop-in — same request and response shape as Anthropic’s /v1/messages, streaming included. Migrating is a base URL and a key.
  • Routing by task — each project has a default model plus escalation rules (by workflow tag or prompt size), so only the calls that need a bigger model get one.
  • Fallback chains — when a provider errors or times out, the call moves to the next model in the project’s chain.
  • Budgets — a hard monthly spend cap per project.
  • Visibility — every call is logged with model, tokens, cost and fallback hops, and shows up in the DirectStudio dashboard per project.

Connect a project

Each client project gets its own virtual key, issued by the workspace admin together with the project’s routing policy. Then:

ts
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://api.directos.dev',
  apiKey: process.env.DIRECTOS_KEY, // the project's virtual key
});

const message = await client.messages.create({
  model: 'claude-haiku-4-5', // logged as requested; the project's policy picks the model
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Summarize this ticket…' }],
});
bash
curl -X POST https://api.directos.dev/v1/messages \
  -H "x-api-key: $DIRECTOS_KEY" \
  -H 'content-type: application/json' \
  -d '{"model":"claude-haiku-4-5","max_tokens":256,"messages":[{"role":"user","content":"Hi"}]}'

Optional headers

HeaderEffect
x-directos-modelPin a specific model for this call, skipping routing.
x-directos-workflowTag the call, so the project’s workflow-based escalation rules can match it.

Errors and limits

Every error response carries x-directos-error-origin: gateway when DirectOS itself refused or failed (bad key, budget, rate limit), or upstream when it is a provider’s own error relayed as-is. Only gateway errors are worth routing around — an upstream error would fail the same way against the provider directly.

  • Rate limit — 60 requests per minute per virtual key.
  • Budget — once month-to-date spend reaches the project’s cap, calls return 429 until the next calendar month.
  • Privacy — only metadata (model, tokens, cost, timing) is logged by default; prompt and response bodies are stored only if the project opts in.