Skip to content
IQ

curl

Two flags change. The Authorization header carries your gateway key; the URL carries the gateway origin. Request and response shapes follow the provider's format. IQ adds its own response headers and can add IQ fields to the response body. Use this recipe to verify connectivity from a shell or a CI pipeline without an SDK in scope.

Drop-in switch

-H "Authorization: Bearer gw_live_xxxxxxxx"
https://gateway.iq-routing.com/v1/chat/completions

The body shape is the OpenAI /v1/chat/completions shape. The Anthropic shape lives at /v1/messages with the same authorization header.

Verify it routes

#!/usr/bin/env bash
set -euo pipefail

: "${IQ_API_KEY:?set IQ_API_KEY}"

iq_response_file=$(mktemp)
trap 'rm -f "$iq_response_file"' EXIT

curl -sS -i https://gateway.iq-routing.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${IQ_API_KEY}" \
  -d '{
    "model": "auto",
    "messages": [{"role": "user", "content": "Summarise: routing-aware gateway."}],
    "max_tokens": 64
  }' | tee "$iq_response_file"

echo
echo "Request id:"
grep -i '^x-request-id:' "$iq_response_file" | tr -d '\r'

The -i flag prints headers; the grep line surfaces the X-Request-Id value. Paste that into /requests/<uuid> to see the routing decision.

For the Anthropic surface:

curl -sS -i https://gateway.iq-routing.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: ${IQ_API_KEY}" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-haiku-5-5",
    "max_tokens": 64,
    "messages": [{"role": "user", "content": "Say hello."}]
  }'

The Anthropic surface accepts both Authorization: Bearer <key> and x-api-key: <key> for compatibility with the official Anthropic SDK default.

Using capability aliases

Pass cap:<name> in the model field to request a capability; check the x-iq-model response header for the dispatched or recorded model and manage your workspace's overrides at /settings/capabilities.

curl -sS -i https://gateway.iq-routing.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${IQ_API_KEY}" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "cap:reason-heavy",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Plan the migration in three phases."}]
  }'

The -i flag prints the response headers, so you can grep them. When routing telemetry is enabled, this reply can also include x-iq-routing with JSON fields such as chosen_model, chosen_provider and cache_hit. See the capability aliases docs for the full list of default capabilities and how to override them. A workspace owner or admin can override the default capability mapping in the editor at /settings/capabilities.

Common gotchas

The gateway allows up to 600 seconds per provider attempt and 1800 seconds across the fallback loop; streaming limits cover upstream stream readiness rather than the full token stream, so set an explicit client timeout if you need a shorter limit.

The --retry family of flags retries on the entire request. IQ's own rate-limit and daily-budget 429s carry a Retry-After hint; monthly-budget and spend-ceiling 429s do not. Use --retry 0 and have your shell loop respect the header explicitly when it is present:

curl -sS -i --max-time 60 --retry 0 https://gateway.iq-routing.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${IQ_API_KEY}" \
  -d '{"model":"auto","messages":[{"role":"user","content":"Say hello."}],"max_tokens":64}'

When the fallback chain runs out because providers are overloaded or returning server errors, the gateway returns 503. On OpenAI-compatible routes the error body has type: "service_unavailable" and code: "overloaded". The 503 error body on /v1/messages uses overloaded_error as its type. Use your own backoff schedule for this response.

Use jq -n or a heredoc for bodies that contain user content; single quotes work only for fixed bodies.

The CI/CD pattern: store IQ_API_KEY as a secret (your CI system's secrets or your host's environment variables); never inline it. The gateway revokes keys via the dashboard's /keys page; a leaked key is an operator-actionable revocation, not a redeploy.

Try this in the playground

Run this snippet against your gateway key →