Relay API Documentation
Relay is a high-concurrency, edge-optimized inference gateway designed to sit between your client software and upstream foundational AI providers (Anthropic, OpenAI, DeepSeek, Google Vertex). Instead of wrangling disparate provider SDKs, handling provider rate limits, and implementing custom retries, point your application at Relay for instant key pooling, automatic sub-second failover, and exact per-token cost ledgering.
Rotate multiple upstream API keys dynamically with zero downtime. Healthy keys are prioritized automatically.
If an upstream provider returns 429 or 503, Relay seamlessly reroutes the payload through your configured backup model.
Drop Relay straight into Anthropic Claude Code CLI with simple environment variables—no client code patches needed.
https://botliy.online.Quick Start Guide
OpenAI CompatibleConnect your existing OpenAI client library by changing just the baseURL and apiKey. Relay transparently proxies the call to the appropriate provider (e.g., Anthropic, DeepSeek, or OpenAI).
curl https://botliy.online/api/v1/chat/completions \
-H "Authorization: Bearer rly_live_your_relay_key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-7-sonnet",
"messages": [
{"role": "system", "content": "You are a distributed systems architect."},
{"role": "user", "content": "Explain raft consensus in two sentences."}
]
}'Authentication & API Keys
All requests to Relay require authentication using a valid live API key prefixed with rly_live_. Keys are generated in your Dashboard and hashed cryptographically with Argon2id before storing. Relay accepts authentication in two standard header formats:
When creating keys in your dashboard, you can define an optional spend cap (e.g., \$10.00 USD). If the cumulative spend of a key hits that threshold, Relay immediately refuses further requests from that key with HTTP 429 without terminating other keys on your account.
Autonomous Agent CLIs (Claude Code & Codex)
Connect your frontier terminal coding agents directly to Relay. Seamless native emulation for both Anthropic Messages and OpenAI Chat protocols with zero rate-limit headache and transparent credit billing.
Install Claude Code
Recommended method: native PowerShell installer. Alternative: WinGet package manager.
irm https://claude.ai/install.ps1 | iexInstall Git for Windows if you want Claude Code to use Git Bash. Without it, Claude Code will seamlessly use PowerShell.
Create a Relay API Key
Open the API Keys page, create a key (e.g. rly_live_...), and copy it.
Create settings.json
Save this file at C:\Users\YOUR_USERNAME\.claude\settings.json.
New-Item -ItemType Directory "$env:USERPROFILE\.claude" -Force{
"env": {
"ANTHROPIC_API_KEY": "YOUR_RELAY_API_KEY",
"ANTHROPIC_BASE_URL": "https://botliy.online/",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
},
"permissions": {
"allow": [],
"deny": []
}
}Replace YOUR_RELAY_API_KEY with your real key. If you used an older setup, remove any stale apiKeyHelper entries to prevent 401 Unauthorized errors.
Verify and start
claude --version claude doctor cd path-to-your-project claude
Frequently Asked Questions
Use Codex CLI when you want OpenAI/DeepSeek chat completion workflows and the official Codex terminal agent. Use Claude Code when your workflow expects Anthropic-compatible tool calling, Claude Code project behavior, or autonomous multi-file refactoring.
POST /api/v1/chat/completions
OpenAI SchemaStandard chat completion route. Accepts system, user, and assistant messages, alongside temperature, max tokens, and streaming options.
| FIELD | TYPE | REQ | DESCRIPTION |
|---|---|---|---|
| model | string | Yes | Public model ID (e.g. claude-3-7-sonnet) |
| messages | array | Yes | Array of message objects with role and content |
| stream | boolean | No | When true, pushes tokens via SSE |
| temperature | float | No | Sampling temperature 0.0–2.0 (default 0.7) |
| max_tokens | integer | No | Maximum tokens to generate |
curl https://botliy.online/api/v1/chat/completions \
-H "Authorization: Bearer rly_live_your_relay_key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-7-sonnet",
"messages": [
{"role": "system", "content": "You are a distributed systems architect."},
{"role": "user", "content": "Explain raft consensus in two sentences."}
]
}'POST /api/v1/messages & /v1/messages
Anthropic SchemaNative Anthropic format supporting anthropic-version: 2023-06-01, structured system messages, multimodal image inputs, and Anthropic SSE streams.
curl https://botliy.online/api/v1/messages \
-H "x-api-key: rly_live_your_relay_key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-7-sonnet",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Write an enterprise unit test in Jest"}
]
}'POST /api/v1/responses
OpenAI Responses APIDirect endpoint for quick single-turn prompt responses, compatible with OpenAI's Responses endpoint interface.
curl https://botliy.online/api/v1/responses \
-H "Authorization: Bearer rly_live_your_relay_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"input": "Summarize microservice choreography vs orchestration"
}'POST /v1/messages/count_tokens
Context BudgetingAllows client agents and tools to calculate accurate token weights before sending long prompts or multi-file context windows. This does not consume account credits.
curl https://botliy.online/v1/messages/count_tokens \
-H "x-api-key: rly_live_your_relay_key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-7-sonnet",
"messages": [
{"role": "user", "content": "Calculate the exact token count before sending"}
]
}'GET /api/v1/models & /v1/models
View Model MatrixReturns the list of active public models with context window limits and real-time per-million token pricing in standard OpenAI list format.
{
"object": "list",
"data": [
{
"id": "claude-3-7-sonnet",
"object": "model",
"created": 1715000000,
"owned_by": "relay",
"context_window": 200000,
"pricing": {
"prompt": 0.000003,
"completion": 0.000015
}
},
{
"id": "gpt-4o",
"object": "model",
"created": 1715000000,
"owned_by": "relay",
"context_window": 128000,
"pricing": {
"prompt": 0.0000025,
"completion": 0.00001
}
}
]
}Realtime Server-Sent Events (SSE)
When "stream": true is supplied, Relay establishes an immediate HTTP SSE connection. Upstream tokens are piped directly to your client with negligible latency, while billing meters debit credits asynchronously upon stream completion.
curl https://botliy.online/api/v1/chat/completions \
-H "Authorization: Bearer rly_live_your_relay_key" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v3",
"stream": true,
"messages": [{"role": "user", "content": "Stream response in realtime token by token"}]
}'If a streaming connection terminates prematurely (client disconnect or upstream error), Relay calculates tokens generated up to that disconnect moment and logs the exact trace without overcharging.
Smart Routing & Automatic Fallbacks
Relay decouples client-facing model IDs from upstream credentials. When you route through Relay, four intelligent mechanisms ensure maximum uptime:
Assign multiple API keys to a single provider. Primary keys handle traffic first; backup keys are called if limits are reached.
Automatically routes traffic to provider keys exhibiting the lowest sliding 5-minute p95 response times.
If an upstream model encounters global capacity depletion (503/429), the gateway transparently reroutes to your configured fallback model.
Identical system instructions and context windows are hashed with SHA-256 to save latency and token costs on repeated tool iterations.
Rate Limits & Headers
Relay returns explicit rate-limit and correlation headers on every response, ensuring production monitoring systems can track usage:
| HEADER | DESCRIPTION |
|---|---|
| X-Request-Id | Unique correlation ID for audits and trace logs |
| X-Response-Time-Ms | Round-trip execution latency in milliseconds |
| X-RateLimit-Limit-Requests | Maximum RPM for your active plan |
| X-RateLimit-Remaining-Requests | Remaining calls in the sliding 60-second window |
| Retry-After | Recommended wait duration (seconds) on HTTP 429 |
Error Codes & Taxonomy
Relay uses standard HTTP response codes paired with machine-readable JSON error payloads:
| STATUS | ERROR TYPE | MEANING & RESOLUTION |
|---|---|---|
| 400 | invalid_request_error | Malformed JSON or missing model / messages. |
| 401 | authentication_error | Missing, revoked, or expired API key. |
| 402 | insufficient_credits | Credit balance depleted. Top up in Dashboard > Billing. |
| 403 | permission_error | Account suspended or lacks model permission. |
| 404 | not_found_error | Model ID not found or disabled in the Model Matrix. |
| 429 | rate_limit_error | RPM or key spend limit reached. Respect Retry-After. |
| 500 / 502 | gateway_error | Upstream provider failed, all fallbacks exhausted. |
Billing & Credits Guide
Go to BillingRelay uses flexible on-demand credit top-ups designed for engineering teams. Zero card checkout traps, zero surprise recurring subscriptions.
Navigate to Dashboard > Billing and scan the verified UPI QR code using any UPI app (GPay, PhonePe, Paytm, CRED).
Enter the exact paid amount and paste your bank transaction reference (UTR / UPI Ref ID). You can optionally upload a payment screenshot.
Once verified, credits are added directly to your account balance with full audit logs visible in your credit transaction history.