Developers

API Quickstart

JohnRouter exposes an OpenAI-compatible API. Buyers use prepaid credits; provider selection is handled by JohnRouter unless explicitly constrained.

Buyer example

from openai import OpenAI
client = OpenAI(
    base_url="https://api.johnrouter.ai/api/v1",
    api_key="$JOHNROUTER_API_KEY"
)

response = client.chat.completions.create(
    model="deepseek/deepseek-v3",
    messages=[{"role":"user","content":"Hello"}]
)

API keys

Keys are scoped to a buyer workspace and can have expiry and spend limits. Plaintext keys are shown once; only hashes are stored.

Routing controls

cheapest

Favor lowest cost eligible providers.

fastest

Favor low latency.

uptime

Favor proven availability.

privacy

Require matching data policies.

Credits

Inference requires a positive prepaid balance. JohnRouter reserves a maximum request cost, settles actual token usage, then releases unused reservation.

Provider requirements

Provider endpoints must be HTTPS, OpenAI-compatible, support streaming, report usage for streaming and non-streaming requests, publish model capabilities and pass continuous health monitoring.

Core endpoint

POST /api/v1/chat/completions
Authorization: Bearer jr_live_...
Content-Type: application/json

Image generation

Image models use a dedicated endpoint, POST /api/v1/images, with the same API key and prepaid credits. Discover them with GET /api/v1/images/models (they also appear in /api/v1/models with output_modalities: ["image"]). Each generation is metered on the upstream-reported cost and billed all-or-nothing; the response is OpenRouter-compatible.

curl https://johnrouter.com/api/v1/images \
  -H "Authorization: Bearer jr_live_..." \
  -H "Content-Type: application/json" \
  -d '{"model":"black-forest-labs/flux.2-klein-4b","prompt":"a cowboy hat with a wifi symbol, flat vector","aspect_ratio":"1:1","output_format":"png"}'

# → { "created": ..., "data": [{ "b64_json": "...", "media_type": "image/png" }], "usage": { "cost": 0.0147, ... } }