> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Text generation API: protocols and models

> Generate text with LaoZhang API: pick the OpenAI-compatible, Anthropic Messages, or Gemini format, compare models, and read streamed replies.

LaoZhang API serves text models in three request formats with the same API key: OpenAI-compatible Chat Completions, Anthropic Messages, and Gemini's native generateContent. For a new project, use Chat Completions; it works with the largest number of text models.

| Item | Details |
| - | - |
| API host | `https://api.laozhang.ai` |
| New project | Send `model` and `messages` to `POST /v1/chat/completions` and read the reply from `choices[0].message.content` |
| Existing SDK app | If it already uses the Anthropic SDK, Claude Code, or the Google Gen AI SDK, keep its request format and change only the base URL and API key |
| Formats per model | The **Endpoints** column in the [model catalog](/en/models) |
| Prices | See [Common text models](#common-text-models) |

## Choose a protocol

* **New project, or a client built on the OpenAI SDK or format**: use OpenAI-compatible Chat Completions. See the [OpenAI protocol reference](/en/api-reference/chat-completions).
* **Anthropic SDK, Claude Code, or another Messages client**: use Anthropic Messages. See the [Claude protocol reference](/en/api-reference/claude).
* **Google Gen AI SDK, or code that relies on Gemini's native fields**: use the Gemini format. See the [Gemini protocol reference](/en/api-reference/gemini).

Each format has its own endpoint:

```text theme={null}
OpenAI-compatible    POST https://api.laozhang.ai/v1/chat/completions
Anthropic Messages   POST https://api.laozhang.ai/v1/messages
Gemini native        POST https://api.laozhang.ai/v1beta/models/{model}:generateContent
```

When you use an SDK, set the OpenAI SDK's base URL to `https://api.laozhang.ai/v1`. The Anthropic SDK and the Google Gen AI SDK take the host root, `https://api.laozhang.ai`, and add the path themselves.

Claude models have not been listed on LaoZhang API since September 24, 2026. We will post an [announcement](/en/changelog) if they return. The Anthropic Messages endpoint still serves the models marked for it in the pricing configuration, including:

* `glm-5.2` (token groups `default` and `claude_code`)
* `deepseek-v4-pro`
* `deepseek-v4-flash`

The request and response structures differ, so switching formats means changing both the request code and the parser:

| | OpenAI-compatible | Anthropic Messages | Gemini native |
| - | - | - | - |
| Model ID | `model` in the body | `model` in the body | URL path |
| Input | `messages` | `messages` and required `max_tokens` | `contents[].parts[]` |
| System prompt | `system` role message | Top-level `system` | `systemInstruction` |
| Reply text | `choices[0].message.content` | `text` blocks in `content[]` | `text` in `parts[]` |
| Streaming | `"stream": true` | `"stream": true` | `streamGenerateContent` |

A model marked with two formats, such as `gemini-3.8-flash` (Chat Completions and Gemini native), accepts either one, but each request must use a single format's fields.

## Common text models

Prices below come from LaoZhang API's public pricing as of September 24, 2026. They are list prices for the `default` token group, in US dollars per 1M tokens. The [model catalog](/en/models) has cache-read prices, other models, and other token groups.

| Model ID | Formats | Input / output |
| - | - | - |
| `gpt-6-luna` | OpenAI-compatible | \$0.1 / \$0.5 |
| `gpt-6-sol` | OpenAI-compatible | \$2 / \$10 |
| `gpt-6.1-sol` | OpenAI-compatible | \$2 / \$10 |
| `gpt-6-astra` | OpenAI-compatible | \$10 / \$50 |
| `gpt-5.6-luna` | OpenAI-compatible | \$0.2 / \$1.2 |
| `gpt-5.6-terra` | OpenAI-compatible | \$2 / \$12 |
| `gpt-5.6-sol` | OpenAI-compatible | \$4 / \$20 |
| `gpt-5.4-mini` | OpenAI-compatible | \$0.75 / \$4.5 |
| `gpt-5.4` | OpenAI-compatible | \$2.5 / \$15 |
| `gemini-4-argon` | OpenAI-compatible, Gemini native | \$2 / \$10 |
| `gemini-3.8-flash` | OpenAI-compatible, Gemini native | \$0.75 / \$3.75 |
| `gemini-3.6-flash` | OpenAI-compatible, Gemini native | \$1.5 / \$7.5 |
| `gemini-3.5-flash-lite` | OpenAI-compatible, Gemini native | \$0.3 / \$2.502 |
| `glm-5.2` | OpenAI-compatible, Anthropic Messages | See catalog |
| `deepseek-v4-pro` | OpenAI-compatible, Anthropic Messages | See catalog |
| `deepseek-v4-flash` | OpenAI-compatible, Anthropic Messages | See catalog |
| `o3-pro` | Responses | See catalog |

* GPT-6 models, GPT-5.6 models, and `gpt-5.4` charge a higher tier for long inputs. The catalog's [tiered pricing](/en/models#tiered-pricing) table lists the thresholds and prices.
* To choose among the three GPT-6 models, and for OpenAI's rules on their parameters and tool calling in Chat Completions, see the [GPT-6 launch announcement](/en/announcements/gpt-6-launch-2026-09).
* The OpenAI models in the table also work with the Responses endpoint, `POST /v1/responses`, and the `o3-pro` series supports only Responses.
* Tool calling with GPT-6 Astra or GPT-6.1 Sol requires Responses. For GPT-6.1 Sol's other parameter differences, see the [GPT-6.1 Sol launch announcement](/en/announcements/gpt-6-1-sol-2026-10). See [OpenAI models on LaoZhang API](/en/api-reference/openai) for examples.
* For Gemini 4 Argon's thinking levels and launch pricing, see the [Gemini 4 Argon launch announcement](/en/announcements/gemini-4-argon-2026-10).
* To send images to a vision model, see the [Image understanding API](/en/api-capabilities/vision-understanding).

## Send your first request

Create an API key in [Token management](https://api.laozhang.ai/token). Set its billing mode to Usage first (按量优先, recommended) or Usage-based (按量计费), and make sure its token group can call the model you want. Then export the key:

```bash theme={null}
export LAOZHANG_API_KEY="YOUR_LAOZHANG_API_KEY"
```

These examples send one message to `gpt-5.4-mini` in the OpenAI-compatible format. Install the SDK before you run them:

* Python: run `python -m pip install openai`.
* Node.js: run `npm install openai`, save the code as `chat.mjs`, and run it with `node chat.mjs`.

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl --fail-with-body --max-time 120 \
      "https://api.laozhang.ai/v1/chat/completions" \
      -H "Authorization: Bearer $LAOZHANG_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-5.4-mini",
        "messages": [{"role": "user", "content": "Reply only with: connected"}]
      }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        api_key=os.environ["LAOZHANG_API_KEY"],
        base_url="https://api.laozhang.ai/v1",
        timeout=120.0,
        max_retries=0,
    )
    response = client.chat.completions.create(
        model="gpt-5.4-mini",
        messages=[{"role": "user", "content": "Reply only with: connected"}],
    )
    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import OpenAI from "openai";

    const client = new OpenAI({
      apiKey: process.env.LAOZHANG_API_KEY,
      baseURL: "https://api.laozhang.ai/v1",
      timeout: 120_000,
      maxRetries: 0,
    });
    const response = await client.chat.completions.create({
      model: "gpt-5.4-mini",
      messages: [{ role: "user", content: "Reply only with: connected" }],
    });
    console.log(response.choices[0].message.content);
    ```
  </Tab>
</Tabs>

The reply should be `connected`. To try another model, change `model` to an ID whose **Endpoints** include OpenAI-compatible. The SDK examples turn off automatic retries so that your application decides when to send a request again.

## Stream the reply

Add `"stream": true` to receive the reply as server-sent events while the model writes it. Each format streams a little differently:

* **OpenAI-compatible**: append each `choices[0].delta.content` in order and skip chunks that have no `choices` or `content`. The stream ends with `data: [DONE]`. [Stream a response](/en/api-reference/chat-completions#stream-a-response) has complete cURL and Python examples and the raw events.
* **Anthropic Messages**: text arrives as `delta.text` in `content_block_delta` events, and the reply is complete only after `message_stop`. See [Stream the response](/en/api-reference/claude#stream-the-response).
* **Gemini native**: replace `generateContent` with `streamGenerateContent` and add `?alt=sse`. Each event carries a partial response with `candidates`; see [Stream the reply](/en/api-reference/gemini#stream-the-reply).
* If the connection closes before the end marker, the text you received is incomplete; treat the request as failed or send it again. With cURL, add `-N` to turn off output buffering.

## Troubleshoot common errors

* **404 with `/v1/v1` in the URL**: the SDK base URL repeats part of the path. Use `https://api.laozhang.ai/v1` for the OpenAI SDK and `https://api.laozhang.ai` for the Anthropic and Google Gen AI SDKs.
* **Model not available, 403, or 404**: copy the exact model ID from the catalog, confirm that your key's token group includes the model, and check that the model supports the format you are sending. For example, `o3-pro` works only through Responses, tool calling with `gpt-6-astra` requires Responses, and GPT models do not accept Gemini native requests. See [model availability](/en/faq/model-availability).
* **400**: a Messages request without `max_tokens` is a common cause. Otherwise, go back to the minimal request, then add optional fields one at a time and fix the field the error names.
* **401**: the API key is wrong, the header is malformed, or the environment variable is not set in the current shell.
* **Empty reply**:
  * Chat Completions: check `message.tool_calls` and `finish_reason`.
  * Messages: read `content[]` by block `type` instead of taking `content[0]`.
  * Gemini: check `finishReason` and `promptFeedback`.
* **Truncated reply**: any of these values means the reply hit the output limit. Raise the model's output limit or shorten the input.
  * Chat Completions: `finish_reason` of `length`.
  * Messages: `stop_reason` of `max_tokens`.
  * Gemini: `finishReason` of `MAX_TOKENS`.
* **429**: read the error body to tell rate or concurrency limits apart from insufficient balance. If you still have balance, see [why a request can fail with remaining balance](/en/faq/balance-insufficient).

## Before you go to production

1. Pin the model ID and protocol in configuration, and test a model change like any other release.
2. Run a sample of your own prompts through two or three candidate models and compare answer quality, latency, and token usage. [Choose a model](/en/api-reference/chat-completions#choose-a-model) describes the comparison.
3. Test normal requests, streaming, and error handling. Keep retries in one layer, either the SDK or your application.
4. In [call logs](https://api.laozhang.ai/log), check each request's model, input and output tokens, and charge.

## Related documentation

* [OpenAI protocol: Chat Completions](/en/api-reference/chat-completions)
* [Use OpenAI models with LaoZhang API](/en/api-reference/openai)
* [Claude protocol: Anthropic Messages](/en/api-reference/claude)
* [Gemini protocol: generateContent](/en/api-reference/gemini)
* [API integration guide](/en/api-manual): keys, base URLs, Responses, and images
* [Model catalog and pricing](/en/models)
* Upstream documentation: [OpenAI text generation](https://developers.openai.com/api/docs/guides/text), [Anthropic Messages API](https://platform.claude.com/docs/en/api/messages), and [Gemini text generation](https://ai.google.dev/gemini-api/docs/text-generation)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.