Disclosure: I work on qcode.cc, an API relay for Claude Code and Codex CLI. Everything below works against any relay, including ours, and the script is MIT-licensed.
If you use Claude Code, Codex CLI, or an OpenAI SDK through a third-party API — after setting ANTHROPIC_BASE_URL, a custom Codex base_url, or a "configure third-party inference" endpoint — you are trusting a middleman with three things: your latency, your bill, and the claim that the model you asked for is the model you got. Most relays answer all three with adjectives ("fast", "stable", "official"). Here is an API relay integrity test that replaces the adjectives with numbers you can rerun yourself.
1. Measure time to first token, not "ping"
What you feel in Claude Code is time to first token (TTFT) on a streamed request, not ICMP ping and not total request time. Measure it on a tiny, fixed task so model speed does not drown the network signal:
- stream on,
max_tokens16, prompt "Reply with exactly: pong" - a random nonce in every prompt, so nothing comes from a response cache
- at least 5 runs; report median and p90, never the best run
- write down where you tested from. Latency to a relay is mostly geography.
Reasoning models stream reasoning deltas before visible text. Count the first reasoning or tool delta as the first token, or every reasoning model will look broken.
2. Count errors next to latency
A relay that answers in 1 second but fails one request in five is not fast; your agent will retry and you will wait anyway. Record the HTTP status of every run. Also watch for transport errors (TLS EOF, resets): they do not show up as a status code at all, and many dashboards silently drop them.
3. Check that a bad key gets a JSON 401
Send a request with a deliberately invalid key. A well-behaved API returns 401 or 403 with a JSON error body. A 200 HTML landing page, a redirect, or a Cloudflare challenge tells you the endpoint was not built for programmatic clients, and it is exactly what breaks automated probes and confuses SDK error messages.
4. Verify prompt caching actually works, and read usage correctly
Prompt caching is where long Claude Code sessions save most of their money, so it is worth checking. Send the same long system prefix (over about 1,024 tokens) with cache_control: {"type": "ephemeral"} twice. On the second call, usage.cache_read_input_tokens should be greater than zero. Anthropic's own prompt caching docs describe the same cache_control field.
The trap: with caching on, input_tokens only counts the uncached part of the prompt. In one of my test runs the prompt was 2,785 tokens in total, and the second call reported cache_read_input_tokens: 2560, so input_tokens alone looked tiny. If you (or a leaderboard) compare input_tokens against the prompt length, you will accuse honest providers of under- or over-counting. The real prompt size is:
input_tokens + cache_creation_input_tokens + cache_read_input_tokens
That sum should be stable across two identical calls.
5. Treat "model authenticity" as signals, not proof
People rightly worry about relays quietly serving a cheaper model. Things you can check:
- the
modelfield in the response echoes what you requested; - features that only the real upstream supports behave correctly: prompt caching with cache-read accounting, tool use, extended thinking where the model supports it;
- token counts for the same text are stable across calls.
None of these is proof. A determined cheater can fake a model field. Be suspicious of anyone, relay or tester, who says one test "proves" authenticity. What you can do is make cheating detectable over time: run the same probes regularly from more than one place and publish the raw results.
The script
I put the method into one standard-library Python file: llm-relay-bench. It tests Anthropic Messages (Claude Code), OpenAI Chat Completions, and OpenAI Responses (Codex CLI), reads the key from an environment variable, never writes it to the report, and outputs JSON you can diff or publish.
curl -fsSLO https://raw.githubusercontent.com/ethan-cur/llm-relay-bench/main/relay_bench.py
export LLM_API_KEY=... # read from the environment, never printed or saved
# Claude Code style endpoint (ANTHROPIC_BASE_URL)
python3 relay_bench.py --anthropic https://relay.example.com --anthropic-model <claude-model-id> \
--runs 10 --label "Berlin, home fiber" --out result.json
# OpenAI-compatible + Codex Responses
python3 relay_bench.py --openai https://relay.example.com/v1 --openai-model <model-id> \
--responses https://relay.example.com/v1 --responses-model <model-id>
Useful options: --auth x-api-key for Anthropic's header style, --pause seconds between runs (default 6, to stay under a typical 10 requests/minute cap), --key-env MY_VAR if you do not want to use LLM_API_KEY.
If you run it against any relay, ours included, pull requests with raw JSON results are welcome. Please say if you work for the relay you tested.
If your relay "does not work" at all, start one step earlier with llm-endpoint-check, which explains 404 vs 401 vs "HTML instead of JSON" for a given Base URL.
Contact: hi@qcode.cc
Comments
Join the discussionNo comments yet. Be the first to comment.