cd /news/ai-tools/relayrouter-api-troubleshooting-why-… · home › topics › ai-tools › article
[ARTICLE · art-180833] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=· neutral

RelayRouter API Troubleshooting: Why Claude Code Gets HTML Instead of JSON

A developer documented a debugging method for RelayRouter API failures where Claude Code and OpenAI-compatible SDKs receive HTML instead of JSON, producing the error 'Unexpected token `<` in JSON at position 0'. The writeup advises checking the exact requested URL, status code, and Content-Type header before involving an SDK, and notes that Claude Code requires an Anthropic Messages-compatible route such as /v1/messages rather than an OpenAI-compatible /v1/chat/completions endpoint alone.

recommendation

Before debugging SDK code, curl the exact endpoint with -i and check status code and Content-Type; confirm the gateway exposes /v1/messages for Claude Code and /v1/chat/completions for OpenAI-compatible clients.

more in playbook: Running AI in production
by read4 min views6 publishedDec 3, 2026

The error looks like a JSON problem:

Unexpected token < in JSON at position 0

But the < is usually the clue. Your client expected an API response and received an HTML page instead.

I start debugging this by asking one question: What exact URL did the client request?

A gateway can serve a website, a dashboard, and an API from related addresses. A valid domain does not necessarily point to a valid API route. There is also a second trap: Claude Code and an OpenAI-compatible SDK do not speak the same API protocol.

For an OpenAI-compatible Chat Completions client, the RelayRouter quickstart documents this base URL:

https://api.relayrouter.ai/v1

The client then calls:

POST https://api.relayrouter.ai/v1/chat/completions

Claude Code is different. It expects an Anthropic Messages-compatible gateway, including a route such as /v1/messages. An OpenAI-compatible /v1/chat/completions endpoint alone is insufficient. Check that the gateway explicitly supports the Anthropic Messages protocol before configuring Claude Code.

Those are two separate checks:

Imagine configuring a client with a site URL:

https://example-gateway.com

That address may serve a landing page. If the client sends a request to a path the site does not recognize, the server or a reverse proxy may return an HTML error page. The SDK tries to parse that page as JSON, reaches the first < in <!doctype html>, and fails.

Other possible causes include a login redirect, a stale hostname, a missing API prefix, or a proxy that replaces an upstream error with its own HTML page.

The JSON parser is reporting the symptom. The response’s status code, content type, and final URL tell you what happened.

Here is a minimal request to an OpenAI-compatible Chat Completions route. Replace YOUR_MODEL_ID with a model ID from your current dashboard.

curl -i -sS https://api.relayrouter.ai/v1/chat/completions \
  -H "Authorization: Bearer $RELAYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {"role": "user", "content": "Reply with one sentence."}
    ]
  }'

Look at the first lines of the response:

Content-Type: application/json means you reached an API response, even if it contains an error.Content-Type: text/html means you probably reached a web page, redirect target, or proxy error page.401 points toward the key or authorization header.404 can mean the route or model ID is wrong.429 calls for a check of rate limits, account status, and retry behavior. Do not paste a real key into a post or issue. Keep it in an environment variable and remove secrets from any logs you share.

This is where a URL fix can look successful but still leave the integration broken.

Client Typical API route Request format
OpenAI-compatible SDK /v1/chat/completions model plusmessages in OpenAI Chat Completions format
Claude Code /v1/messages Anthropic Messages format and headers

Anthropic’s gateway compatibility guide lists /v1/messages as the relevant route for a gateway reached through ANTHROPIC_BASE_URL. It also describes headers and streaming behavior that the gateway must handle.

So the statement “just add /v1 and Claude Code will work with any OpenAI-compatible API” is incomplete. The gateway needs an Anthropic-compatible route or a tested translation layer. Anthropic’s gateway overview also notes that it does not support routing Claude Code to non-Claude models through a gateway.

I use this sequence because each step removes one class of uncertainty:

/v1. Content-Type before involving an SDK. For an OpenAI-compatible Python client, the route looks like this:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["RELAYROUTER_API_KEY"],
    base_url="https://api.relayrouter.ai/v1",
)

response = client.chat.completions.create(
    model=os.environ["RELAYROUTER_MODEL"],
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

print(response.choices[0].message.content)

For Claude Code, follow Anthropic’s gateway connection instructions after confirming that your chosen gateway exposes the Anthropic Messages API. Its ANTHROPIC_BASE_URL is the gateway origin that Claude Code uses to reach /v1/messages; it is not interchangeable with an OpenAI SDK’s base_url.

A base URL is only one part of the contract:

working integration =
  correct host
  + correct path
  + correct protocol
  + valid credential
  + available model

If the response starts with HTML, inspect the route before changing application code. If the route returns JSON but Claude Code still fails, inspect protocol compatibility next.

The RelayRouter quickstart repository contains OpenAI-compatible examples and a troubleshooting guide. Use its current model and endpoint instructions alongside the service dashboard.

If you are debugging an API integration, compare the request URL, response status, and content type before sharing logs. You can discuss the setup in the Discord community.

Disclosure: This post includes an affiliate / referral link. If you register through it, I may earn a commission at no extra cost to you.

If you want to try the service, here is the RelayRouter registration link.

── more in #ai-tools 4 stories · sorted by recency
── more on @relayrouter 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/relayrouter-api-trou…] indexed:0 read:4min 2026-12-03 · —