invalid_api_key or 404 error usually means the request never reached LaoZhang API or the base URL path is wrong; the key itself is rarely the problem. A LaoZhang API key only works with LaoZhang API hosts, set as shown below.
Match the error to its cause
Configure each SDK
Each SDK builds request paths differently. The OpenAI SDK appends only the resource name, so its base URL must include/v1. The Anthropic SDK appends /v1/messages itself, so adding /v1 produces /v1/v1/messages and a 404.
- OpenAI SDK
- Anthropic SDK
- Google Gen AI SDK
LAOZHANG_API_KEY environment variable before you run these. To see which models accept the Anthropic format, check the model list in Claude protocol.
Configure with environment variables
Many tools read OpenAI’s standard environment variables, so you can leave the base URL out of your code:- Your code, a
.envfile, and the shell each set a different URL. - A third-party client still has an old provider saved.
- The process wasn’t restarted and still reads the old variables.
https://api.laozhang.ai/v1 as the API URL, your LaoZhang API key, and a full model ID from the model catalog.
Confirm the setup with one request
data array means the key and host are both correct; the array lists the models this token can call. If you still get a 401, check in Tokens that the token is enabled, hasn’t expired, and has quota left, or create a new token and try again.
Fallback hosts
All three hosts accept the same API key, paths, and parameters. Only the hostname changes:- Default:
api.laozhang.ai - Direct connections from Europe or North America:
api-vip.laozhang.ai - When
api.laozhang.aican’t be reached:api2.laozhang.ai
Still stuck?
Email hi@laozhang.ai with:- the request time and time zone;
- the full request URL (without the key) and the SDK you use;
- the HTTP status and the full error body;
- the first 6 and last 4 characters of the key.