Trust & Security · As of 2026-11-25

Choosing a QCode Endpoint: api vs asia vs us, and How to Measure AI API Latency Yourself

QCode has three access domains: api.qcode.cc (the default entry), asia.qcode.cc (Asia) and us.qcode.cc (North America / Europe). All three share the same account and the same cr_ key and expose identical paths; only the network route differs. The reliable way to choose is not someone else's numbers but your own: on the machine where your tools actually run, measure connection timings with curl -w and time-to-first-token (TTFT) with a streaming request, take the median of at least 10 samples per domain, and compare. This guide gives copy-paste scripts plus endpoint switching and failover setups for Claude Code, Codex and the SDKs (as of 2026-11-25).

QCode is an independent third-party API service, not affiliated with Anthropic, OpenAI or any model vendor. This page deliberately publishes no latency or uptime figures; trust your own measurements.

Updated 2026-11-26

Key facts

  • Three domains, one key: api.qcode.cc, asia.qcode.cc and us.qcode.cc share your account and key. Swap only the hostname; the paths (/api, /openai/v1, /openai) stay the same.
  • Start with api.qcode.cc: it is the default entry point. If your network is in Asia, measure asia.qcode.cc as well; if you are in North America or Europe, measure us.qcode.cc too.
  • Measure two things: network timings (DNS, TCP, TLS, first byte) and model TTFT. The first reflects the endpoint; the second also depends on the model and its reasoning effort.
  • Compare medians and P90, never single runs: at least 10 samples, repeated at different times of day.
  • Failover is client-side: switching domains is a manual step. Code can try the three domains in order, but switching does not help with 400, 401, 402 or 429.
  • Verify with real work: after choosing a domain, watch error rates and TTFT in your normal sessions, not just in the test script.

What each domain is for

Domain Role Try it first if
api.qcode.cc Default entry You want the default
asia.qcode.cc Asia Your network is in East or Southeast Asia
us.qcode.cc North America / Europe Your network is in North America or Europe

Per-tool URLs differ only in the hostname:

Tool / protocol api asia us
Claude Code (Anthropic) https://api.qcode.cc/api https://asia.qcode.cc/api https://us.qcode.cc/api
OpenAI-compatible clients https://api.qcode.cc/openai/v1 https://asia.qcode.cc/openai/v1 https://us.qcode.cc/openai/v1
Codex CLI https://api.qcode.cc/openai https://asia.qcode.cc/openai https://us.qcode.cc/openai

Three reminders: no trailing slash on any base URL; no /v1 in the Codex URL (Codex appends /responses itself); and European readers may also want our Europe AI coding API latency notes.

Step 1: Confirm the path and key work

Run a self-test before timing anything. POST with your key and no body: 400 means path and key are fine (the body is just missing); 401 is a key problem; 404 is a wrong path prefix; 402 with a *_cost_limit_exceeded code means your quota is used up.

KEY="cr_your_key"
for host in api.qcode.cc asia.qcode.cc us.qcode.cc; do
  printf '%-15s ' "$host"
  curl -s -o /dev/null -w '%{http_code}\n' -X POST "https://$host/api/v1/messages" \
    -H "Authorization: Bearer $KEY"
done

Opening a bare prefix such as https://api.qcode.cc/api in a browser returns an HTML page with HTTP 200. That does not prove the API path works.

Step 2: Measure network timings with curl -w

curl -w prints cumulative timings in seconds, all measured from the start of the request:

  • time_namelookup: DNS resolution done
  • time_connect: TCP connection established
  • time_appconnect: TLS handshake done
  • time_starttransfer: first response byte received (TTFB)
  • time_total: request finished

Because they are cumulative, TCP handshake ≈ connect − namelookup, TLS ≈ appconnect − connect, and server-side handling ≈ starttransfer − appconnect. The script below sends 10 requests per domain and prints the median TTFB. It reuses the bodyless self-test (HTTP 400), which returns before any model output:

KEY="cr_your_key"
for host in api.qcode.cc asia.qcode.cc us.qcode.cc; do
  for i in $(seq 1 10); do
    curl -s -o /dev/null -X POST "https://$host/api/v1/messages" \
      -H "Authorization: Bearer $KEY" \
      -w "$host %{http_code} dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total}\n"
    sleep 1
  done
done | tee qcode-latency.txt

for host in api.qcode.cc asia.qcode.cc us.qcode.cc; do
  printf '%s median ttfb: ' "$host"
  grep "^$host " qcode-latency.txt | sed 's/.*ttfb=\([0-9.]*\).*/\1/' | sort -n \
    | awk '{a[NR]=$1} END {print a[int((NR+1)/2)] "s"}'
done

On Windows, run it in Git Bash or WSL. In PowerShell, call curl.exe, not the curl alias.

Step 3: Measure time-to-first-token with a streaming request

What you feel in a coding tool is the gap between pressing Enter and seeing the first token. This Python script uses only the standard library. It sends several streaming requests to each domain and records three moments: response headers received, first content delta (TTFT) and end of stream. It supports both the Anthropic and OpenAI protocols:

#!/usr/bin/env python3
"""qcode_ttft.py - compare time-to-first-token across QCode endpoints (stdlib only)."""
import json, os, statistics, time, urllib.request

KEY = os.environ["QCODE_KEY"]
PROTO = os.environ.get("PROTO", "anthropic")  # anthropic | openai
MODEL = os.environ.get("MODEL", "claude-haiku-5-5" if PROTO == "anthropic" else "gpt-6.2-sol")
RUNS = int(os.environ.get("RUNS", "10"))
HOSTS = os.environ.get("HOSTS", "api.qcode.cc asia.qcode.cc us.qcode.cc").split()

def build(host):
    msgs = [{"role": "user", "content": "Reply with the single word: ok"}]
    if PROTO == "anthropic":
        url = f"https://{host}/api/v1/messages"
        body = {"model": MODEL, "max_tokens": 64, "stream": True, "messages": msgs}
        headers = {"x-api-key": KEY, "anthropic-version": "2023-06-01"}
    else:
        url = f"https://{host}/openai/v1/chat/completions"
        body = {"model": MODEL, "stream": True, "messages": msgs}
        headers = {"Authorization": f"Bearer {KEY}"}
    headers["content-type"] = "application/json"
    return urllib.request.Request(url, json.dumps(body).encode(), headers, method="POST")

def has_token(line):
    if not line.startswith(b"data:") or line.strip() == b"data: [DONE]":
        return False
    try:
        ev = json.loads(line[5:])
    except ValueError:
        return False
    if PROTO == "anthropic":
        return ev.get("type") == "content_block_delta"
    choices = ev.get("choices") or [{}]
    return bool((choices[0].get("delta") or {}).get("content"))

def run_once(host):
    t0 = time.perf_counter()
    with urllib.request.urlopen(build(host), timeout=120) as resp:
        t_head, t_first = time.perf_counter() - t0, None
        for line in resp:
            if t_first is None and has_token(line):
                t_first = time.perf_counter() - t0
    return t_head, t_first, time.perf_counter() - t0

def ms(v):
    return "   n/a" if v is None else f"{v * 1000:6.0f}"

for host in HOSTS:
    heads, firsts, totals, errors = [], [], [], 0
    for _ in range(RUNS):
        try:
            h, f, t = run_once(host)
            heads.append(h); totals.append(t)
            if f is not None:
                firsts.append(f)
        except Exception as exc:
            errors += 1
            print(f"  {host}: {type(exc).__name__}: {exc}")
        time.sleep(1)
    med = lambda v: statistics.median(v) if v else None
    p90 = lambda v: statistics.quantiles(v, n=10)[-1] if len(v) >= 2 else None
    print(f"{host:14} headers_ms {ms(med(heads))}  ttft_ms {ms(med(firsts))}  "
          f"ttft_p90_ms {ms(p90(firsts))}  total_ms {ms(med(totals))}  errors {errors}/{RUNS}")

Run it:

export QCODE_KEY="cr_your_key"
python3 qcode_ttft.py                                          # Anthropic protocol, claude-haiku-5-5 by default
PROTO=openai MODEL=gpt-6.2-sol RUNS=20 python3 qcode_ttft.py   # OpenAI protocol

This script calls a real model. Each run uses very few tokens, but they count against your quota. Use a small, inexpensive model, a fixed short prompt and a low max_tokens, and keep every parameter identical across the three domains.

Step 4: Read the results correctly

  1. Compare medians and P90. A single run is dominated by random jitter, and averages get dragged by one or two outliers. The median shows the typical case; P90 shows how slow the slow cases are.
  2. Separate network time from model time. Switching domains only changes the path between you and QCode. The ttft − headers gap is mostly upstream model time, which changes with the model, reasoning effort and context length. Only compare endpoints with the same model and prompt.
  3. Cold and warm connections differ. The script opens a new connection each time, so every sample includes DNS, TCP and TLS. Tools like Claude Code reuse connections within a session and pay the handshake once, so over a long session TTFT and stability matter more than handshake time.
  4. Error rate beats a few milliseconds. If one domain occasionally times out or drops streams, don't pick it even if its median is slightly faster. For dropped streams, see stream closed before completion.
  5. Test at different times. Run a round in the morning and another in the evening, or whenever you usually work.
  6. Test where the tool runs. Proxies, corporate networks and the region of a cloud server all change routing. Measure on the machine your agent actually uses.
  7. Ping is not HTTPS latency. ICMP may be blocked or routed differently. Trust HTTPS measurements.
  8. Watch DNS. What api.qcode.cc resolves to depends on your resolver. Check with nslookup api.qcode.cc or dig +short api.qcode.cc; if the result looks poor, switch to a nearby resolver or pin asia / us directly.

The scripts above show what your network is doing at one moment. Repeat a short round during your usual working hours and compare the medians; keep the domain that wins on both runs and has the lower error rate.

Step 5: Switch endpoints in your tools

Claude Code reads ANTHROPIC_BASE_URL. Change the hostname and start a new session:

export ANTHROPIC_BASE_URL=https://asia.qcode.cc/api
export ANTHROPIC_AUTH_TOKEN=cr_your_key
claude

Or put it in the env block of ~/.claude/settings.json (if the file holds your key, keep its permissions tight and never commit it):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://asia.qcode.cc/api",
    "ANTHROPIC_AUTH_TOKEN": "cr_your_key"
  }
}

Set these variables in one place only, so shell exports and config files don't silently override each other. For quick switching, define shell aliases:

alias claude-asia='ANTHROPIC_BASE_URL=https://asia.qcode.cc/api claude'
alias claude-us='ANTHROPIC_BASE_URL=https://us.qcode.cc/api claude'

For a GUI switcher, see the CC Switch guide. QCode also publishes a one-click install script for Claude Code.

Codex CLI: edit base_url in ~/.codex/config.toml, save, and reopen codex:

[model_providers.qcode]
name = "qcode"
base_url = "https://asia.qcode.cc/openai"
wire_api = "responses"
requires_openai_auth = true

To try another domain once without editing the file, override the key with -c (values are parsed as TOML):

codex -c 'model_providers.qcode.base_url="https://us.qcode.cc/openai"'

Cursor, Cline and other IDE plugins: change the hostname in the Anthropic or OpenAI base URL setting to asia or us. The key stays the same.

Step 6: Client-side failover in the SDKs

Switching domains is a manual step: if the primary domain misbehaves, use the same key and path on another domain. In your own code you can automate that by trying the three domains in order:

import os
import anthropic

BASES = ["https://api.qcode.cc/api", "https://asia.qcode.cc/api", "https://us.qcode.cc/api"]
RETRYABLE = (anthropic.APIConnectionError, anthropic.InternalServerError)  # network errors and 5xx

def create_with_failover(**kwargs):
    last_exc = None
    for base in BASES:
        client = anthropic.Anthropic(base_url=base, api_key=os.environ["QCODE_KEY"],
                                     max_retries=1, timeout=120)
        try:
            return client.messages.create(**kwargs)
        except RETRYABLE as exc:
            last_exc = exc  # try the next domain
    raise last_exc

msg = create_with_failover(model="claude-sonnet-5-5", max_tokens=512,
                           messages=[{"role": "user", "content": "Summarize this diff"}])

The OpenAI SDK version is the same idea: use .../openai/v1 base URLs and catch openai.APIConnectionError and openai.InternalServerError. A few rules:

  • Fail over only on network errors and 5xx. 400 (bad request), 401 (bad key), 402 (quota used up) and 429 (concurrency or rate limit) won't improve on another domain, because all three share the same key and quota.
  • Mind double billing. If a request fails after the upstream model has started generating, a retry is billed again. Stream long tasks and keep what you received before the failure.
  • Don't race domains. Sending the same request to all three at once multiplies cost and triggers rate limits sooner.

Claude Code has related environment variables of its own: API_TIMEOUT_MS (per-request timeout, default 600000 ms) and CLAUDE_CODE_MAX_RETRIES (retry count, default 10). For gateway-specific errors, see Claude Code gateway errors 2026.

FAQ

Do the three domains share the same key, quota and prices?

Yes. They share one account and key and differ only in routing. Billing stays at the official price times the service multiplier, currently ×1.0 for Anthropic and OpenAI models; live rates are on /models.

Which domain should I use by default?

Start with api.qcode.cc, the default entry. Measure asia.qcode.cc and us.qcode.cc from your own network, and let your medians and error rates decide.

How do I fail over between domains?

Switching is a manual step: use the same key and path on another domain. If you need automatic failover, implement it in your client as shown above.

Does latency testing use my quota?

The curl test in Step 2 sends bodyless requests that return 400 and produce no model output. The TTFT script in Step 3 calls a real model and uses a few tokens per run, which count against your quota, so use a small model and a short prompt. If you want to confirm how rejected requests are billed, compare your quota before and after a short self-test.

My network timings look fast, so why does Claude Code still feel slow?

TTFT depends on more than the network. Reasoning effort, context length and the number of tool calls all add waiting time. If network timings are already low, try a lower effort or a faster model.

Do I need to restart my tool after switching endpoints?

Yes. Claude Code reads ANTHROPIC_BASE_URL at startup, so start a new session. For Codex, reopen codex after editing config.toml.

Will switching endpoints fix a 429?

No. A 429 means a concurrency or rate limit, and all three domains share your key's limits. Run fewer agents in parallel or retry later.

How do I know the real latency of my own requests?

Measure it on the machine where your tools run, using the scripts above, and repeat the test at the times you usually work. That is the latency that matters.

Test it on your own network with the Starter plan

Latency only means something when it is measured on your network, with your tools. The QCode Starter plan starts from $9 per 30 days (see /pricing for the current price) and includes a $5 daily quota. The same key works on all three domains, which is plenty to run the scripts above and compare endpoints during real work. For a short test without a subscription, see the packs on /pay-as-you-go.

Test it on your own network with the Starter plan

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack