Why your LLM gateway returns 404: the /v1 rule for Claude Code vs OpenAI SDKs

2026-12-04来源 dev.toEnglish

If you've pointed a tool at a custom LLM gateway and got a 404, the cause is usually not your key or the model. It's one path segment: /v1.

I maintain a gateway called HZAPI (public brand HZ AI) and this is the most common support question I see. The rule below is true for any gateway that serves both the Anthropic Messages and OpenAI-compatible APIs.

The rule

Client Base URL
Claude Code, Anthropic SDK, Cline (Anthropic mode) https://api.hzapi.vip (no /v1)
OpenAI SDKs, Codex, Cursor, Cherry Studio, Dify, n8n https://api.hzapi.vip/v1

Why: Anthropic clients treat the Base URL as a root and append /v1/messages themselves, so a trailing /v1 produces /v1/v1/messages. OpenAI clients expect the Base URL to already end in /v1 and append /chat/completions or /responses, so a bare root produces /chat/completions with no version. Both are 404s that look identical.

Separate "client config" from "key/group" with curl

export HZAPI_API_KEY="sk-xxxx" # placeholder curl -sS https://api.hzapi.vip/v1/models -H "Authorization: Bearer $HZAPI_API_KEY" 

A 200 with a model array means network, TLS, key and group binding are fine; the problem is in the client. (On HZAPI a key is bound to one group, and the group decides which models you can call. Take model IDs from this call, not from guesswork.)

The three protocols side by side:

# Chat Completions curl -sS https://api.hzapi.vip/v1/chat/completions \ -H "Content-Type: application/json" -H "Authorization: Bearer $HZAPI_API_KEY" \ -d '{"model":"deepseek-v4-pro","messages":[{"role":"user","content":"ping"}]}' # Responses curl -sS https://api.hzapi.vip/v1/responses \ -H "Content-Type: application/json" -H "Authorization: Bearer $HZAPI_API_KEY" \ -d '{"model":"gpt-6.2-astra","input":"ping"}' # Anthropic Messages curl -sS https://api.hzapi.vip/v1/messages \ -H "x-api-key: $HZAPI_API_KEY" -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{"model":"claude-fable-5-2","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}' 

(The model IDs above are the examples from the gateway's own guide; availability depends on your key's group and is listed on its model plaza.)

Claude Code

export ANTHROPIC_BASE_URL="https://api.hzapi.vip" export ANTHROPIC_AUTH_TOKEN="$HZAPI_API_KEY" claude --model claude-fable-5-2 

From Claude Code's own docs:

  • ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer ...; ANTHROPIC_API_KEY is sent as X-Api-Key. Don't set both.
  • Setting only ANTHROPIC_BASE_URL leaves a saved claude.ai login as the active credential, so you still send the wrong credential to the gateway.
  • Run /status and check for the Anthropic base URL line and the credential source.
  • An auth-conflict warning means a login and a gateway credential are both active: /logout keeps the gateway credential.
  • 400 ... Extra inputs are not permitted: try CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1.

OpenAI-style tools

Python

import os from openai import OpenAI client = OpenAI(api_key=os.environ["HZAPI_API_KEY"], base_url="https://api.hzapi.vip/v1") print(client.responses.create(model="gpt-6.2-astra", input="One-line summary of idempotent retries").output_text) 

Dify: install the official OpenAI-API-compatible plugin; API Base URL is the /v1 address; Model Name must match an ID from /v1/models exactly; raise the default 4096 context size to the model's real limit.

n8n: in the OpenAI credential change Base URL (default https://api.openai.com/v1) to the /v1 address and leave Organization ID empty. The credential test calls {Base URL}/models.

Cherry Studio: add a custom provider with an OpenAI endpoint (/v1) and/or an Anthropic endpoint (root), fetch the model list, add models, and turn the provider's enable switch on.

Cline / Continue: Anthropic mode takes the root; OpenAI-compatible mode takes /v1. Continue defaults to /responses for o-series and gpt-5 models; add useResponsesApi: false if your model doesn't support it.

Cursor: Settings → Models → API Keys → Override OpenAI Base URL = the /v1 address. It's global (affects Cursor's own OpenAI-family models too) and doesn't apply to Tab.

Error table

Status Usual cause Fix
404 /v1 doubled or missing; /chat/completions pasted into the Base URL See the rule above
401 Truncated key, whitespace, key from a different site Re-copy it
model_not_found Model not in the key's group Use IDs from GET /v1/models
403 Balance or sub-token quota exhausted Check the console
410 Retired host still configured Use the current gateway host
429 Burst concurrency or tight retry loop Exponential backoff with jitter
Timeout / 502 / 504 Long reasoning before first token; a proxy cutting idle connections at 60s Stream, 180s+ timeout, check proxy_read_timeout

When asking any provider's support for help, send only the last 4 characters of the key, the model name and the time, never the full key.

Samples

Runnable minimal samples (Python and Node OpenAI SDKs, curl for all three protocols) plus tutorials for Claude Code, Dify, n8n, Cursor, Cline, Continue and Cherry Studio, in English and Chinese:

https://github.com/Sakcyb/hzapi-examples (MIT, no real keys; .env.example uses sk-xxxx)

Official docs for the gateway: https://hziai.cc/guide/

Disclosure: I maintain HZAPI. The rule in this post applies to any gateway serving both protocol families. I make no claims about pricing or model availability here; see the gateway's model plaza and pricing page.

原文:https://www.a8q9.cn/en/article/why-your-llm-gateway-returns-404-the-v1-rule-for-claude-code-vs-openai-sdks-dc25d6.html

相关文章