Guides

AI gateway

Call models from every major vendor with your Pikeway key, in the OpenAI Chat Completions, Anthropic Messages or OpenAI Responses format. You pay per token from the same balance as every other API.

Point any OpenAI or Anthropic client at Pikeway by changing two things: the base URL and the key. Every model in the model catalog works with all three formats.

Endpoints
POST /ai/v1/chat/completions
OpenAI Chat Completions, streaming included.
POST /ai/v1/messages
Anthropic Messages, streaming included. anthropic-version and anthropic-beta headers are passed through.
POST /ai/v1/messages/count_tokens
Anthropic token counting. Needs a key; not billed.
POST /ai/v1/responses
OpenAI Responses.
GET /ai/v1/models
Model list with prices and capabilities. No key needed.

OpenAI Chat Completions

POSThttps://gw.pikeway.ai/ai/v1/chat/completions
bash
curl https://gw.pikeway.ai/ai/v1/chat/completions \
  -H "Authorization: Bearer $PIKEWAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "messages": [{ "role": "user", "content": "Summarize the WBTC market in one line." }]
  }'

# X-Pikeway-Cost: 0.000412
# X-Pikeway-Tokens: 18+52

With "stream": true, the response is passed through as server-sent events. The gateway asks the upstream to include usage at the end of the stream so the call can be billed by tokens.

Anthropic Messages

POSThttps://gw.pikeway.ai/ai/v1/messages
bash
curl https://gw.pikeway.ai/ai/v1/messages \
  -H "Authorization: Bearer $PIKEWAY_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "max_tokens": 512,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Use with Claude Code

Claude Code speaks the Messages format, so two environment variables route it through Pikeway:

bash
export ANTHROPIC_BASE_URL=https://gw.pikeway.ai/ai
export ANTHROPIC_AUTH_TOKEN=pk-…          # your Pikeway key
claude

Claude Code requests models by their dated Anthropic names (e.g. claude-sonnet-4-5-20250929). The gateway resolves these to the canonical catalog name (claude-sonnet-4.5), so you don't need to change any model settings.

OpenAI Responses

POSThttps://gw.pikeway.ai/ai/v1/responses
bash
curl https://gw.pikeway.ai/ai/v1/responses \
  -H "Authorization: Bearer $PIKEWAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "gpt-5", "input": "Write a haiku about toll roads." }'

Model names

Use the id from the catalog or from GET /ai/v1/models as model. Models also accept aliases (such as an OpenRouter-style full id or a short name), and Anthropic-style names are normalized: a date or -latest suffix is dropped and dashes between digits become dots. Usage is always recorded under the canonical name. An unknown model returns 404 unknown model.

bash
curl https://gw.pikeway.ai/ai/v1/models

{
  "object": "list",
  "data": [{
    "id": "claude-sonnet-5",
    "object": "model",
    "owned_by": "anthropic",
    "display_name": "…",
    "context_length": 200000,
    "pricing": { "input_per_mtok": 3, "output_per_mtok": 15 },
    "capabilities": { "tools": true, "streaming": true, "thinking": true }
  }, …]
}

Token billing

  • Each model has an input and an output price per million tokens (input_per_mtok, output_per_mtok). Cost = input tokens × input price + output tokens × output price.
  • Input tokens served from the vendor's prompt cache are billed at the model's cache-read price when it has one.
  • Token counts come from the upstream's usage. Non-streaming responses report them in X-Pikeway-Tokens (input+output) and the cost in X-Pikeway-Cost. For streams the cost is settled when the stream ends; see it in your call log.
  • Requests the upstream rejects (4xx/5xx) are not billed.
  • A request needs a positive balance to start; otherwise it gets 402 insufficient balance.
Sending the same prompt repeatedly? Add X-Pikeway-Cache: 300 to a non-streaming chat completion and identical requests within 5 minutes are answered from cache at 10% of the token price. See Caching.