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

> Source: <https://dev.to/relayrouter/relayrouter-api-troubleshooting-why-claude-code-gets-html-instead-of-json-8cd>
> Published: 2026-12-03 07:38:56+00:00

**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 the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

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` plus`messages` in OpenAI Chat Completions format | 
| Claude Code | `/v1/messages` | Anthropic Messages format and headers | 

Anthropic’s [gateway compatibility guide](https://code.claude.com/docs/en/llm-gateway-protocol) 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](https://code.claude.com/docs/en/llm-gateway) 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:

``` python
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](https://code.claude.com/docs/en/llm-gateway-connect) **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](https://github.com/whale0yep-ai/relayrouter-api-quickstart) 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](https://discord.gg/MEdCarjE).

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](https://relayrouter.app/register?aff=xc9N).
