Skip to main content
An 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.
Set the 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:
If the error persists after you change the URL, look for settings that override each other:
  • Your code, a .env file, 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.
In third-party clients, look for a “Custom API” or “OpenAI-compatible” provider. Enter 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

A 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.ai can’t be reached: api2.laozhang.ai
For the full setup, see Connect your application to LaoZhang API.

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.
Never send the full API key. If the key has appeared in a chat, screenshot, or repository, revoke and replace it first, as described in API key management.