Gateway

AI models

Drop-in OpenAI- and Anthropic-compatible endpoints for every model in the catalog. Point your SDK at the gateway, use your Pikeway key, and pay per token from your balance.

Base URLs
OpenAI SDKs:     https://gw.pikeway.ai/ai/v1
Anthropic SDKs:  https://gw.pikeway.ai/ai

Authentication

Authorization: Bearer pk-… (OpenAI SDKs send this when you pass the key as apiKey) or X-API-Key: pk-…. For Claude Code set ANTHROPIC_BASE_URL=https://gw.pikeway.ai/ai and ANTHROPIC_AUTH_TOKEN=pk-…. Your balance must be above 0.

Billing

The gateway reads token usage from the model's response (or from the final events of a stream) and charges input × input price + cached input × cache price + output × output price, all per million tokens. Responses with status 400 or above are not charged. Prices per model are in GET /ai/v1/models.

Response headers
X-Pikeway-Call-Idstring
Call id.
X-Pikeway-CostUSD
Charged amount. Non-streaming responses only (for streams the cost is known after the last event; see your request logs).
X-Pikeway-Tokensprompt+completion
Token usage, e.g. 812+64. Non-streaming only.
X-Pikeway-CacheHIT | MISS
Only when you opted into the response cache (below).

Chat completions

POST/ai/v1/chat/completions

OpenAI Chat Completions format. The body is passed to the model provider as-is, except that model is mapped to the provider's model id, and streaming requests get stream_options.include_usage = true so the gateway can meter the stream.

Body
modelstringrequired
A model id or alias from /ai/v1/models. Anthropic-style dated names are normalized, e.g. claude-sonnet-4-5-20250929 → claude-sonnet-4.5.
messagesarrayrequired
Chat messages, as in the OpenAI API.
streamboolean
Stream server-sent events. Usage is captured from the stream.
…
Any other OpenAI parameter (tools, temperature, max_tokens…) is forwarded unchanged.
Headers
X-Pikeway-Cacheseconds
Opt into exact-match response caching for non-streaming requests: 1 = 300 s, otherwise the TTL in seconds (max 3600). Cached per account. A hit skips the model and is billed at 10% of the original token cost.
bash
curl https://gw.pikeway.ai/ai/v1/chat/completions \
  -H "Authorization: Bearer $PIKEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "messages": [{"role": "user", "content": "Summarize ERC-4337 in one sentence."}]
  }'

The response is the provider's OpenAI-format response, unchanged:

200 OK
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "openai/gpt-5",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "ERC-4337 adds smart-contract wallets to Ethereum without protocol changes…" },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 17, "completion_tokens": 31, "total_tokens": 48 }
}

Messages (Anthropic)

POST/ai/v1/messages

Anthropic Messages format, for Claude Code and the Anthropic SDKs. anthropic-version and anthropic-beta headers are forwarded. Usage counts input_tokens plus cache reads and cache writes as input; cache reads are billed at the model's cache price.

bash
curl https://gw.pikeway.ai/ai/v1/messages \
  -H "Authorization: Bearer $PIKEWAY_API_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"}]}'
Claude Code
export ANTHROPIC_BASE_URL=https://gw.pikeway.ai/ai
export ANTHROPIC_AUTH_TOKEN=pk-...
claude

Count tokens

POST/ai/v1/messages/count_tokens

Anthropic token counting, forwarded to the model provider. Requires a valid key and is free. Returns the provider's response.

Responses (OpenAI)

POST/ai/v1/responses

OpenAI Responses format. Usage is read from usage (or the response.completed event when streaming); input_tokens_details.cached_tokens are billed at the cache price.

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

List models

GET/ai/v1/models

All enabled models with prices and capabilities. No key needed.

bash
curl https://gw.pikeway.ai/ai/v1/models
200 OK
{
  "object": "list",
  "data": [
    {
      "id": "claude-sonnet-5",
      "object": "model",
      "owned_by": "anthropic",
      "display_name": "Claude Sonnet 5",
      "context_length": 1000000,
      "pricing": { "input_per_mtok": 2, "output_per_mtok": 10 },
      "capabilities": { "tools": true, "streaming": true, "thinking": true }
    }
  ]
}
Model fields
idstring
Use as model in requests.
owned_bystring
Vendor.
context_lengthinteger | null
Context window in tokens.
pricing.input_per_mtok · pricing.output_per_mtoknumber (USD)
Price per million input / output tokens.
capabilitiesobject
tools, streaming, thinking support.

Errors

  • 400 invalid JSON body · missing 'model'
  • 401 missing API key (Authorization: Bearer pk-...) · invalid or revoked API key
  • 402 insufficient balance (balance is 0 or less)
  • 403 key IP / origin restriction
  • 404 unknown model: …
  • 405 POST only
  • 502 upstream LLM request failed: …
  • Errors from the model provider are returned with their original status and body, and are not charged.
More setup recipes are in the AI gateway guide.