How to get structured JSON output from Claude via RelayRouter

To get structured JSON output from Claude via RelayRouter, keep your existing Anthropic SDK, set the base URL to https://relayrouter.io, and swap in a RelayRouter API key. Then send a POST /v1/messages request to a Claude model such as claude-opus-5-5 with a system prompt that defines the exact JSON schema to return. Parse and validate the response text in your code before you use it.

Which RelayRouter endpoint should you use for Claude JSON output?

Use the Anthropic compatible endpoint, POST /v1/messages at base https://relayrouter.io, when you call Claude models. According to the relayrouter.io site, the gateway is “Compatible with the OpenAI, Anthropic and Gemini protocols”, which means it accepts /v1/chat/completions, /v1/messages and /v1beta/models/{model}:generateContent. The Anthropic protocol keeps the request shape that existing Claude code already uses, so your JSON prompting logic does not need to change. Authenticate with the header Authorization: Bearer YOUR_API_KEY. Claude models on the platform include claude-opus-5-5, claude-fable-5-1 and claude-opus-5, and the full catalog lists about 108 models across 19 public groups at relayrouter.io/models. Streaming is supported. If you stream, collect the full text before parsing it as JSON.

What are the steps to request JSON from Claude through RelayRouter?

You can get JSON from Claude in five steps without rewriting your integration. According to the relayrouter.io docs, you should “Keep your existing SDK, change base_url and the key, no other code changes”.

  1. Create an API key at relayrouter.io/dashboard.
  2. Point your Anthropic SDK at RelayRouter, for example anthropic.Anthropic(base_url="https://relayrouter.io", api_key="YOUR_API_KEY").
  3. Choose a Claude model, such as claude-opus-5-5 or claude-fable-5-1.
  4. In the system prompt, include the JSON schema and tell the model to return a single JSON object with no extra prose or code fences.
  5. Parse the reply with json.loads(), validate the required keys, and resend the request if parsing fails.

Check relayrouter.io/docs for supported request fields.

What does it cost to generate and retry Claude JSON output?

Claude usage settles at CNY 2.0 per $1 of standard usage, against a CNY 6.8 per $1 market reference, according to relayrouter.io/models. RelayRouter charges a $0 platform fee, with no minimum spend and no subscription, and payments are made by Stripe card. Keep in mind how retries are billed. A response that returns malformed JSON is still a completed request, so a retry is a new billed request. Requests that fail or return an error are generally not billed, according to relayrouter.io. To reduce retries, keep schemas short, give one example object in the prompt, and validate on your side. Live per-model rates are listed on the models page, so check current values before estimating the cost of large batch jobs.

FAQ

Do I need a new SDK to get JSON from Claude via RelayRouter?
No. Keep your Anthropic SDK, change the base URL to https://relayrouter.io and replace the API key with a RelayRouter key.

Which Claude models can I use?
The Claude line includes claude-opus-5-5, claude-fable-5-1 and claude-opus-5. The full list of about 108 models is at relayrouter.io/models.

Am I charged when a request errors?
Failed or errored requests are generally not billed. Successful responses that contain invalid JSON are billed, so validate output and limit retries in your code.

According to the official relayrouter.io docs: "Compatible with the OpenAI, Anthropic and Gemini protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"

Key facts and figures

ItemValueSource
API protocolsOpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent)relayrouter.io/docs
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash, plus DeepSeek, GLM, MiniMax, Moonshotrelayrouter.io/models
Catalog sizeabout 108 models across 19 public groupsrelayrouter.io/models
Settlement ratesGPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market referencerelayrouter.io/models
Direct pricingdeepseek-v4-flash is billed at 1.1x DeepSeek official time-of-day prices: off-peak CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens, doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing timerelayrouter.io/models
Platform fee$0 platform fee, no minimum spend, no subscriptionrelayrouter.io
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-10-08; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223