> ## 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.

# API Integration Quick Start

> Complete setup guide for integrating LaoZhang API with ChatGPT, Claude, Gemini models. OpenAI SDK compatible - just change base URL. Python/Node.js examples. Start in 5 minutes.

## Before You Start

<Warning>
  **Account Usage Notice**

  Account registration is for **API technical integration testing and enterprise system integration**. The test credits (\$0.5) provided to new accounts are only for:

  * API connectivity verification
  * Development debugging and technical testing
  * Pre-integration functionality verification

  **Not intended for** production environments or public-facing content delivery services.

  Registration requires a Gmail address. Enterprise users can email `hi@laozhang.ai` or contact [@laozhang\_cn](https://t.me/laozhang_cn) on Telegram to request whitelist registration.
</Warning>

Get started with LaoZhang API in just 5 minutes. This guide shows how to:

* Access 200+ AI models through a single unified API
* Use existing OpenAI SDK with minimal code changes
* Integrate with enterprise billing and account credit controls

<Info>
  The documentation default is now `api2.laozhang.ai`. Europe/US users can use the direct overseas route `api-vip.laozhang.ai` without a CDN. The global Cloudflare fallback is `api-cf.laozhang.ai`, but a synchronous request with no response data may reach the approximately 120-second proxy read timeout. See the [API domain migration notice](/en/announcements/api-domain-migration-2026-07).
</Info>

## Step 1: Create Account and Add Credits

### Create Account

<Steps>
  <Step title="Sign Up">
    Visit [LaoZhang API](https://api2.laozhang.ai/register) to create your account with a Gmail address

    New accounts receive \$0.5 test credits for API connectivity verification
  </Step>

  <Step title="Verify Email">
    * Enter your Gmail address
    * Create a secure password (8+ characters)
    * Verify your email via the confirmation link
  </Step>

  <Step title="Access Console">
    Log in to your [console dashboard](https://api2.laozhang.ai/account/profile)

    You'll see:

    * Account balance with test credits
    * Usage statistics and history
    * API key management
  </Step>
</Steps>

### Account Credit and Enterprise Billing

<Tabs>
  <Tab title="Account Credit">
    1. Confirm whether the account is for development testing, internal tools, or production integration
    2. Check account credit and billing status in the console
    3. Contact support before production use or enterprise procurement
  </Tab>

  <Tab title="Billing Review">
    Contact support before adding production credit or arranging enterprise billing:

    * Confirm account type and usage scope
    * Confirm payment method and spending limits
    * Confirm invoice or contract requirements

    Contact support: [hi@laozhang.ai](mailto:hi@laozhang.ai)
  </Tab>

  <Tab title="Enterprise">
    **Enterprise Exclusive Service**:

    * Enterprise quotes through support
    * Invoice support
    * Contract options
    * Dedicated support

    Contact: [hi@laozhang.ai](mailto:hi@laozhang.ai)
  </Tab>
</Tabs>

<Note>
  **Credit Information**:

  * Test credits for connectivity verification
  * Account credit updates after console or support confirmation
  * Enterprise inquiries: [hi@laozhang.ai](mailto:hi@laozhang.ai)
</Note>

## Step 2: Get Your API Key

### Generate Your API Key

<Tabs>
  <Tab title="Use Default Key (Quickest)">
    1. Navigate to [Token Management](https://api2.laozhang.ai/token)
    2. Locate your **Default Token**
    3. Click **Copy** to clipboard

    **Advantage**: Pre-configured and ready to use immediately
  </Tab>

  <Tab title="Create Custom Key">
    1. Click **Create New Token** button
    2. Name your key (e.g., `production-api`, `development-test`)
    3. Optionally set spending limits for budget control
    4. Click **Generate**

    **Advantage**: Better organization for multiple projects or environments
  </Tab>
</Tabs>

<Warning>
  **Security Best Practices**:

  * API keys are shown only once - save securely immediately
  * Never commit keys to version control (use `.gitignore`)
  * Store keys in environment variables
  * Rotate keys periodically for enhanced security
</Warning>

## Step 3: Make Your First API Call

### Test Your Integration

<Tabs>
  <Tab title="Online Playground (Recommended)">
    Test instantly in the [API Playground](https://api2.laozhang.ai/playground):

    1. Select a model (e.g., `gemini-3.6-flash`)
    2. Enter a test prompt: "Hello, introduce yourself"
    3. Click **Send**

    **No code required** - verify your setup works before integrating
  </Tab>

  <Tab title="cURL Command">
    ```bash theme={null}
    # Replace YOUR_API_KEY with your actual key
    curl -X POST https://api2.laozhang.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -d '{
        "model": "gemini-3.6-flash",
        "messages": [
          {"role": "system", "content": "You are a helpful AI assistant"},
          {"role": "user", "content": "What can you help me with?"}
        ]
      }'
    ```

    Actual latency depends on the selected model, input length, network, and current route load.
  </Tab>
</Tabs>

### Integration Configuration

<Card title="Remember These Three Things" icon="key">
  ```yaml theme={null}
  # API Base URL
  base_url: https://api2.laozhang.ai/v1

  # API Key (starts with sk-)
  api_key: sk-xxxxxxxxxxxxxx

  # Model Name (plug and play)
  model: gemini-3.6-flash  # or gemini-3.5-flash-lite, claude-sonnet-5, etc.
  ```
</Card>

### Complete Examples in Different Languages

<Tabs>
  <Tab title="Python (Most Common)">
    ```python theme={null}
    # Install: pip install openai
    from openai import OpenAI

    # Initialize client
    client = OpenAI(
        api_key="Your API Key",  # Get from LaoZhang API
        base_url="https://api2.laozhang.ai/v1"  # Integration URL
    )

    # Examples of calling different models
    def test_models():
        models = [
            "gemini-3.5-flash-lite",  # Low latency and high throughput
            "claude-sonnet-5",  # Coding and agents
            "gemini-3.6-flash"  # General multimodal work
        ]

        for model in models:
            try:
                response = client.chat.completions.create(
                    model=model,
                    messages=[
                        {"role": "system", "content": "You are a helpful AI assistant"},
                        {"role": "user", "content": "Introduce yourself in one sentence"}
                    ],
                    temperature=0.7,
                    max_tokens=100
                )
                print(f"{model}: {response.choices[0].message.content}")
                print(f"Tokens used: {response.usage.total_tokens}\n")
            except Exception as e:
                print(f"{model} call failed: {e}\n")

    if __name__ == "__main__":
        test_models()
    ```

    <Tip>
      **Best Practice**: Store API key in environment variables

      ```python theme={null}
      import os
      client = OpenAI(
          api_key=os.getenv("LAOZHANG_API_KEY"),
          base_url="https://api2.laozhang.ai/v1"
      )
      ```
    </Tip>
  </Tab>

  <Tab title="Node.js / TypeScript">
    ```javascript theme={null}
    // Install: npm install openai
    import OpenAI from 'openai';

    // Initialize client
    const client = new OpenAI({
      apiKey: process.env.LAOZHANG_API_KEY || 'Your API Key',
      baseURL: 'https://api2.laozhang.ai/v1'
    });

    // Streaming output example (real-time response)
    async function streamChat() {
      const stream = await client.chat.completions.create({
        model: 'gemini-3.6-flash',
        messages: [
          { role: 'system', content: 'You are a helpful AI assistant' },
          { role: 'user', content: 'Please write a simple React component' }
        ],
        stream: true,  // Enable streaming
        temperature: 0.7
      });

      // Output word by word
      for await (const chunk of stream) {
        process.stdout.write(chunk.choices[0]?.delta?.content || '');
      }
    }

    // Concurrent calls to multiple models
    async function compareModels(prompt) {
      const models = ['gpt-5.6', 'claude-sonnet-5', 'gemini-3.6-flash'];

      const promises = models.map(model =>
        client.chat.completions.create({
          model,
          messages: [{ role: 'user', content: prompt }],
          max_tokens: 100
        })
      );

      const results = await Promise.all(promises);
      results.forEach((result, index) => {
        console.log(`\n${models[index]}:\n${result.choices[0].message.content}`);
      });
    }

    // Run examples
    streamChat().catch(console.error);
    ```
  </Tab>

  <Tab title="Curl / Command Line">
    ```bash theme={null}
    # Basic call
    curl -X POST https://api2.laozhang.ai/v1/chat/completions -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "gemini-3.6-flash", "messages": [{"role": "user", "content": "Hello"}]}'

    # Streaming output (SSE)
    curl -X POST https://api2.laozhang.ai/v1/chat/completions -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "claude-sonnet-5", "messages": [{"role": "user", "content": "Write a Python quicksort"}], "stream": true}'

    # Image generation
    curl -X POST https://api2.laozhang.ai/v1/images/generations -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "gpt-image-2", "prompt": "A cute kitten", "n": 1, "size": "1024x1024"}'
    ```
  </Tab>
</Tabs>

## Next Steps

Congratulations! You've successfully integrated LaoZhang API. Next you can:

<CardGroup cols={2}>
  <Card title="View API Documentation" icon="book" href="/en/api-manual">
    Learn about complete API interface documentation
  </Card>

  <Card title="Explore Model List" icon="bot" href="/en/api-capabilities/model-info">
    View all supported AI models
  </Card>

  <Card title="Integrate into Apps" icon="plug" href="/en/scenarios/engineering/langchain">
    Integrate LaoZhang API into various tools
  </Card>

  <Card title="View Usage Statistics" icon="chart-line" href="https://api2.laozhang.ai/log">
    Monitor usage in console
  </Card>
</CardGroup>

## Common Questions Quick Reference

<AccordionGroup>
  <Accordion title="How to tell if integration is successful?">
    **Three signs**:

    1. API call returns normal results (no errors)
    2. Response time under 1 second
    3. Can see call records in console

    View call records: [Usage Logs](https://api2.laozhang.ai/log)
  </Accordion>

  <Accordion title="How to choose the right model?">
    **Choose by scenario**:

    **Programming Development**:

    * First choice: `claude-sonnet-5`
    * Alternative: `gpt-5.6-terra`

    **Article Writing**:

    * First choice: `gpt-5.6`
    * Alternative: `claude-sonnet-5`

    **Quick Response**:

    * First choice: `gemini-3.6-flash`
    * Alternative: `gpt-5.6-luna`

    **Cost Sensitive**:

    * First choice: `gemini-3.5-flash-lite`
    * Alternative: `gpt-5.6-luna`
  </Accordion>

  <Accordion title="What if my API key is leaked?">
    **Immediate actions**:

    1. Go to [Token Management](https://api2.laozhang.ai/token)
    2. Revoke the compromised key immediately
    3. Generate a new API key
    4. Update the key in all your applications

    **Prevention measures**:

    * Always use environment variables
    * Never hardcode keys in source code
    * Set spending limits per key
    * Rotate keys every 90 days
  </Accordion>

  <Accordion title="What happens when credits run out?">
    **Options available**:

    1. Confirm account credit with your account owner or support
    2. Switch to a current lower-cost model (for example, `gemini-3.5-flash-lite` or `gpt-5.6-luna`)
    3. Optimize your usage with `max_tokens` limits

    **Cost management tips**:

    * Monitor usage in the console dashboard
    * Set budget alerts
    * Use streaming for better user experience
  </Accordion>

  <Accordion title="What payment methods are supported?">
    **Enterprise billing options**:

    * Contract or email-confirmed billing arrangement
    * Bank transfer for enterprise accounts
    * Invoice and account credit review

    **Enterprise users**: Contact [hi@laozhang.ai](mailto:hi@laozhang.ai) for invoicing and contract options.
  </Accordion>
</AccordionGroup>

<Info>
  Tip: Save your API key properly and check usage logs in the console regularly. Every request has message history for reasonable cost optimization.
</Info>
