AI proxy
POST /api/ai-proxy
Use this streaming endpoint for OpenAI, Anthropic, and OpenAI-compatible providers. It returns server-sent events (SSE).
Request
{
"provider": "openai" | "anthropic" | "custom",
"model": "provider model ID",
"messages": [{ "role": "user", "content": "Hello" }],
"max_tokens": 1000,
"temperature": 0.7
}Messages and parameters
- Use OpenAI-style messages. Roles:
system,developer,user,assistantfor OpenAI and compatible providers;system,user,assistantfor Anthropic, where system messages are sent as Anthropic's system prompt. - Up to 100 messages of up to 32,000 characters each.
max_tokensis capped at 8,192 (default 1,000). temperaturedefaults to 0.7; 0 is honoured. It is limited to 0–2, or 0–1 for Anthropic.
Guards
- Gateway-key or Supabase-JWT authentication.
- Tenant-active and subscription-status check before an upstream call.
- Configured model allowlist, request limits, rate check, and estimated monthly budget reservation.
- Prompt and response bodies are proxied but not stored in Gatekeeper usage logs.
A 402 response indicates an inactive subscription or budget threshold reached. A 429 indicates a rate limit; a 503 can indicate an unavailable budget check. A 502 with upstream_status means the provider rejected the request (for example an invalid provider key); nothing is charged against the budget. Costs are estimates, and provider charges remain your responsibility. Rate checks fail open during an Upstash outage.