Skip to main content
Use https://api2.laozhang.ai to call LaoZhang API. OpenAI clients use a base URL ending in /v1; Google Gen AI and Anthropic clients use the host root. Choose the format your application already uses, then select a model available to your API key’s group.

Get an API key

Create a model API key in Token management. Check its group, balance, and model permissions in Models and pricing. Set the key as an environment variable in the terminal where you will run the examples:
Replace the placeholder with your key. Keep credentials on your server, out of browser bundles, source control, and public logs. Account management AccessTokens are separate credentials; use the balance query guide for account-data requests. The examples use gpt-5.4-mini for text, gemini-3.8-flash for native Gemini text, and gpt-image-2-vip for images. If your token group uses another model, copy its exact ID from the console.

Send a text request

Chat Completions accepts a messages array. Use Bearer authentication and a JSON request body:
The answer appears in 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.

OpenAI SDK

The OpenAI SDK builds the endpoint path, so set its base URL to https://api2.laozhang.ai/v1 without adding /chat/completions.
Install the SDK:
These examples disable automatic retries so your application can decide when to repeat a request. Add optional parameters according to the selected model’s documentation. Sampling controls, output limits, structured output, and tools are model-specific; see the Chat Completions reference.

Responses API

The Responses API uses input in the request and output in the response. Its request body is different from Chat Completions.
For raw JSON, collect the text values from content items whose type is output_text within 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. For applications that need conversation history, retain the messages your next request requires. Server-side state, previous_response_id, and built-in tools depend on the selected model and endpoint. See the OpenAI Responses reference for upstream field definitions and the Data Policy for data handling.

Generate an image

Send a JSON prompt to the Images generation endpoint:
The response is JSON. For this model, read the image bytes from data[0].b64_json. Install Pillow with python -m pip install pillow, then save the image:
Open the saved file to view the generated image. For a complete Python SDK example and model options, see Generate an image.

Edit an image

Place a reference image named input.png in your current directory. Upload it with the instructions as multipart form data:
The @ syntax uploads the file contents. Let cURL set the multipart content type and boundary; do not add Content-Type: application/json to this request. Install Pillow with python -m pip install pillow if needed, then save the returned image:
Compare the saved image with your reference. For the Python SDK upload and more details on results, see Edit an image. Image dimensions, quality settings, and output formats depend on the model; use the matching model guide when adding these options.

Call Gemini with its native API

Gemini’s native API uses contents[].parts[] rather than OpenAI messages:
Read the text parts in candidates[].content.parts[]. If no text is present, inspect finishReason and promptFeedback. For the Google Gen AI SDK, use the host root https://api2.laozhang.ai with api_version="v1beta". The SDK adds the model path and API key header. The Gemini reference includes a complete Python example, both authentication header options, and image-input instructions.

Call Claude with its native API

Applications built around Anthropic content blocks use:
Set the Anthropic SDK base URL to https://api2.laozhang.ai. Follow the Claude integration guide for the model ID, required headers, and message format. Native Anthropic content blocks and OpenAI message objects use different request and response structures.

More API operations

Resolve common errors

Correct invalid requests before retrying. For temporary failures, use bounded backoff and avoid stacking SDK retries with application retries. A client timeout does not cancel generation or establish whether a charge occurred. Check call logs before resubmitting an image request. If you need support, provide the 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, task, and one of these documentation links:
  • skill.md: integration instructions for coding tools.
  • llms.txt: an index for finding the relevant page.
  • llms-full.txt: the full public documentation export.
Start with the index if your tool has a limited context window. Supply credentials through the environment instead of pasting them into prompts.

API references