A
Platform

AI Gateway

Multi-provider chat (Anthropic / OpenAI / Echo) with cost + rate-limit tracking.

How it works

A single chat endpoint routes to the configured upstream provider, normalises the response shape, and records every call as a metric (`ai.tokens.input`, `ai.tokens.output`, `ai.cost.usd`, `ai.latency_ms`) plus a span. Per-project monthly cost ceiling enforced — once exceeded, calls return 402 until the next billing cycle. The `Echo` provider is a deterministic stub for tests.

What this lets you do

  • Don't expose your raw provider keys to every app — proxy through Funnel
  • Track AI spend per project, per model, per use case
  • Hard cost ceiling prevents runaway bills
  • Switch providers without code changes — flip a config

Get it running

  1. 1 Open `AI settings`, paste your Anthropic / OpenAI key
  2. 2 Set a monthly cost ceiling
  3. 3 Use `POST /v1/ai/chat` from your app with a Funnel API key

Code examples

curl -X POST https://funnel.example.com/v1/ai/chat \
  -H "Authorization: Bearer st_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "messages": [
      { "role": "system", "content": "You are a senior SRE." },
      { "role": "user",   "content": "Summarise the last hour of error logs for service=api." }
    ]
  }'

# Returns: { content, usage: { input_tokens, output_tokens, cost_usd } }
Where to find it
/app/p/:org/:project/ai
Open in app →