https://api.laozhang.ai/v1; the Google Gen AI and Anthropic SDKs use the host root and add their own paths.
All three domains accept the same API key, paths, and parameters, so switching changes only the hostname. The console opens on each of them too. Pick the request format your application already uses, then choose a model that your API key’s group can call.
Get an API key
Create an API key in Token management; the console calls it a token. When you create it, you choose its group and billing mode. The group decides which models the key can call. For the billing mode, choose Usage first (按量优先, recommended): a key in this mode can call both the usage-based text models and the per-call image model used below. Billing, token groups, and invoices explains both settings. Set the key as an environment variable in the terminal where you will run the examples:gpt-5.4-minifor textgemini-3.8-flashfor native Gemini requestsglm-5.2for Anthropic Messagesgpt-image-2-vipfor images
Send a text request
Chat Completions takes amessages array. Send your API key as a Bearer token, with a JSON body:
choices[0].message.content; for this prompt, expect connected. Replace the message content with your own prompt to use the same request in your application. The OpenAI protocol reference covers message fields, streaming, and model-specific options.
OpenAI SDK
The OpenAI SDK builds the endpoint path, so set its base URL tohttps://api.laozhang.ai/v1 without adding /chat/completions.
- Python
- Node.js
Install the SDK:
o3-pro, GPT Image, and the speech models.
Move an existing OpenAI app
An application that already uses the OpenAI SDK needs three changes: the API key and base URL in the client, shown below, and themodel value in each request. The rest of your request code stays the same.
OPENAI_API_KEY and OPENAI_BASE_URL:
- Model IDs. A model name that works with OpenAI may have a different ID or group on LaoZhang API. Copy exact IDs from Models and pricing; the OpenAI models guide lists the other differences from calling OpenAI directly.
- Optional parameters. Sampling controls, output limits, structured output, and tool settings vary by model. Start with the required fields, then add the options your application uses. If a request returns an unsupported-parameter error, remove or adjust the field it names.
- Retries. Keep retry logic in one place. If both the SDK and your application retry, one user action can produce several API calls.
- Results. Run the minimal request above, then find it in call logs and confirm the model, token usage, and charge.
Responses API
The Responses API takesinput in the request and returns an output array. Its request body differs from Chat Completions, so an application that switches must update both the request and the response parser.
- cURL
- Python
text values from content items of type output_text inside the output array. The SDK’s output_text helper does this for you. Other output items can contain reasoning or tool calls, so the first item is not necessarily the text answer.
LaoZhang API supports OpenAI’s Responses API, so OpenAI text models such as GPT-6, GPT-5.6, GPT-5.4, and o3-pro can use it. Before you move a model from another vendor to this endpoint, send a minimal request to confirm it works.
Server-side conversation state, previous_response_id, and built-in tools also depend on the model; if your application needs conversation history, keep the messages that your next request requires. The OpenAI Responses reference defines the upstream fields, and the Data Policy covers data handling.
Generate or edit an image
Both Images endpoints return adata array. Depending on the model, each item holds the image as Base64 in b64_json or as a download link in url.
The examples use gpt-image-2-vip, which is billed per call while the text examples are usage-based. A key set to Usage first can call both; if an image request is rejected, check that the key’s billing mode is Usage first or Per-call (按次计费).
Generate an image
Send a JSON prompt to the generation endpoint:Edit an image
Place a reference image namedinput.png in your current directory, then upload it with your instructions as multipart form data:
@ syntax uploads the file contents. Let cURL set the multipart content type and boundary; do not add Content-Type: application/json to this request.
Save the result
The response file is JSON, not an image. Save this script assave_images.py; it uses only the Python standard library:
data, for example generation-1.png. It handles:
- Base64 that starts with a
data:image/...;base64,prefix or lacks trailing=padding. urlresults, which it downloads without your API key. Save URL results promptly and keep your own copy.
Call Gemini with its native API
Gemini’s native API usescontents[].parts[] rather than OpenAI messages:
candidates[].content.parts[]. If no text is present, inspect finishReason and promptFeedback.
For the Google Gen AI SDK, use the host root https://api.laozhang.ai with api_version="v1beta". The SDK adds the model path and API key header. The Gemini protocol reference includes a complete Python example, both authentication header options, and instructions for image, PDF, and audio input. To analyze the frames and audio of an MP4 video, see the Video understanding API.
Call the Anthropic Messages API
Applications built on the Anthropic Messages format, including the Anthropic SDKs, send requests to/v1/messages:
- Required fields:
model,messages, andmax_tokens. - System prompt: put it in the top-level
systemfield rather than inmessages. - Response: the
contentarray can holdtext,thinking, andtool_useblocks. - Answer text: read the blocks whose
typeistextinstead of assuming that the first block is the answer.
glm-5.2, available in thedefaultandclaude_codetoken groups, closely matches the behavior of Anthropic’s own Messages API.deepseek-v4-proanddeepseek-v4-flashare also marked for this endpoint.
base_url="https://api.laozhang.ai" and your LaoZhang API key; the SDK adds /v1/messages. The Claude protocol reference covers the SDK, streaming, and tool use.
More API operations
- Models API: discover model IDs for your application.
- Embeddings: turn text into vectors.
- Audio transcription: upload audio and receive a transcript.
- Moderation: submit content for classification.
Resolve common errors
Correct invalid requests before retrying. For temporary failures, use bounded backoff and avoid stacking SDK retries on top of application retries.
A client timeout does not cancel generation or show whether a charge occurred. Check call logs before you resubmit an image request.
For support, email hi@laozhang.ai or message @laozhang_cn on Telegram with the request time, model, endpoint, token group, and redacted error. Billing and refunds follow the Terms.
Use these docs in an AI coding tool
Give your coding assistant the target model, the task, and one of these files:- skill.md: connection rules and minimal requests for coding assistants, in English.
- llms.txt and llms-full.txt: a page index and a full-text export of the documentation. Both currently cover the Chinese documentation.
API references
LaoZhang API references:- Text generation API: choose a protocol and model
- OpenAI models: endpoints and SDK setup
- OpenAI protocol: Chat Completions
- Claude protocol: Anthropic Messages
- Gemini protocol: generateContent
- Images API: generate and edit images
- Models API
- OpenAI: API reference, Chat Completions, Responses, and models
- Anthropic: Messages API
- Google: Gemini API documentation and generateContent reference