Skip to main content

Why Choose LaoZhang API?

LaoZhang API is a unified AI API gateway that provides seamless access to 200+ AI models through a single OpenAI-compatible interface. Access GPT-4, Claude, Gemini, DeepSeek and more with one API key.

Platform Features

OpenAI Compatible Mode

LaoZhang API uses OpenAI-compatible format, allowing you to easily call ChatGPT, Claude, and 200+ AI models from China: Supported Model Providers:
  • 🤖 OpenAI: gpt-4o, gpt-5-chat-latest, gpt-3.5-turbo, etc.
  • 🧠 Anthropic: claude-sonnet-4-20250514, claude-opus-4-1-20250805, etc.
  • 💎 Google: gemini-2.5-pro, gemini-2.5-flash, etc.
  • 🚀 xAI: grok-4-0709, grok-3, etc.
  • 🔍 DeepSeek: deepSeek-r1, deepSeek-v3, etc.
  • 🌟 Alibaba: Qwen series models
  • 💬 Moonshot: Kimi models, etc.

Feature Support

✅ Supported Features:
  • 💬 Chat Completions: Chat Completions interface
  • 🖼️ Image Generation: gpt-image-1, flux-kontext-pro, flux-kontext-max, etc.
  • 🔊 Audio Processing: Whisper transcription
  • 📊 Embeddings: Text vectorization
  • Function Calling: Function Calling
  • 📡 Streaming: Real-time responses
  • 🔧 OpenAI Parameters: temperature, top_p, max_tokens, etc.
  • 🆕 Responses Endpoint: Latest OpenAI features
❌ Unsupported Features:
  • 🔧 Fine-tuning interface
  • 📁 Files management interface
  • 🏢 Organization management interface
  • 💳 Billing management interface

Easy Model Switching

Core Advantage: One Codebase, Multiple Models After running with OpenAI format, simply change the model name to switch to other large models:
# Use GPT-4o
response = client.chat.completions.create(
    model="gpt-4o",  # OpenAI model
    messages=[...]
)

# Switch to Claude, everything else stays the same!
response = client.chat.completions.create(
    model="claude-3.5-sonnet",  # Just change model name
    messages=[...]
)

# Switch to Gemini
response = client.chat.completions.create(
    model="gemini-1.5-pro",  # Just change model name
    messages=[...]
)
This design allows you to easily compare different model effects, or flexibly switch models based on cost and performance needs, without rewriting code!

Quick Start - Using ChatGPT API in China

Get API Key (China-Specific)

  1. Visit LaoZhang API Console
  2. Log in to your account
  3. Click “Add” on the token management page to create an API Key
  4. Copy the generated API Key for interface calls

View Request Examples

On the token management page, you can quickly get code examples in various programming languages: Steps:
  1. Go to Token Management Page
  2. Find the row with the API Key you want to use
  3. Click the 🔧wrench icon (tool icon) in the “Actions” column
  4. Select “Request Example” from the pop-up menu
  5. View complete code examples in the following languages:
LaoZhang API Token Management Interface Supported Programming Languages:
  • cURL - Command-line testing
  • Python (SDK) - Using official OpenAI library
  • Python (requests) - Using requests library
  • Node.js - JavaScript/TypeScript
  • Java - Java application development
  • C# - .NET application development
  • Go - Go language development
  • PHP - Web development
  • Ruby - Ruby application development
  • And more languages…
Code Example Features:
  • Complete and runnable: Copy and paste to use
  • Parameter descriptions: Detailed parameter configuration
  • Error handling: Includes exception handling logic
  • Best practices: Follows development standards for each language
Developers are encouraged to check the backend request examples first. These examples are updated in real-time based on the latest API versions, ensuring code accuracy and usability.

Basic Information

API Endpoints

  • Primary endpoint: https://api.laozhang.ai/v1
  • Backup endpoint: https://api-cf.laozhang.ai/v1

Authentication Method

All API requests need to include authentication information in the Header:
Authorization: Bearer YOUR_API_KEY

Request Format

  • Content-Type: application/json
  • Encoding: UTF-8
  • Request Method: POST (for most interfaces)

Core Interfaces

1. Chat Completions

Create a chat completion request, supports multi-turn conversations. Request Endpoint
POST /v1/chat/completions
Request Parameters
ParameterTypeRequiredDescription
modelstringYesModel name, e.g., gpt-3.5-turbo
messagesarrayYesArray of conversation messages
temperaturenumberNoSampling temperature, between 0-2, default 1
max_tokensintegerNoMaximum tokens to generate
streambooleanNoWhether to return streaming, default false
top_pnumberNoNucleus sampling parameter, between 0-1
nintegerNoNumber of generations, default 1
stopstring/arrayNoStop sequences
presence_penaltynumberNoPresence penalty, between -2 to 2
frequency_penaltynumberNoFrequency penalty, between -2 to 2
Message Format
{
  "role": "system|user|assistant",
  "content": "Message content"
}
Complete Code Examples
  • cURL
  • Python (SDK)
  • Python (requests)
  • Node.js
  • Java
  • C#
  • Go
  • PHP
  • Ruby
curl -X POST "https://api.laozhang.ai/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {"role": "system", "content": "You are a helpful AI assistant."},
      {"role": "user", "content": "Hello! Please introduce yourself."}
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'
Response Example
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1699000000,
  "model": "gpt-3.5-turbo",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}

2. Text Completions

Kept for compatibility with legacy interfaces, Chat Completions is recommended. Request Endpoint
POST /v1/completions
Request Parameters
ParameterTypeRequiredDescription
modelstringYesModel name
promptstring/arrayYesPrompt text
max_tokensintegerNoMaximum generation length
temperaturenumberNoSampling temperature
top_pnumberNoNucleus sampling parameter
nintegerNoNumber of generations
streambooleanNoStreaming output
stopstring/arrayNoStop sequences

3. Embeddings

Convert text to vector representation. Request Endpoint
POST /v1/embeddings
Request Parameters
ParameterTypeRequiredDescription
modelstringYesModel name, e.g., text-embedding-ada-002
inputstring/arrayYesInput text
encoding_formatstringNoEncoding format, float or base64
Complete Code Examples
  • cURL
  • Python (SDK)
  • Python (requests)
  • Node.js
curl -X POST "https://api.laozhang.ai/v1/embeddings" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-ada-002",
    "input": "This is a text example that needs to be vectorized"
  }'

4. Images

Generate, edit, or transform images. Generate Images
POST /v1/images/generations
Request Parameters
ParameterTypeRequiredDescription
modelstringYesModel name, recommended gpt-image-1
promptstringYesImage description prompt
nintegerNoNumber to generate, default 1
sizestringNoImage size: 1024x1024, 1792x1024, 1024x1792
qualitystringNoQuality: standard or hd
stylestringNoStyle: vivid or natural
Recommended to use gpt-image-1 model for image generation. For more image generation features and parameter descriptions, please see GPT Image Generation detailed documentation.
Complete Code Examples
  • cURL
  • Python (SDK)
  • Node.js
curl -X POST "https://api.laozhang.ai/v1/images/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "A cute orange kitten sitting in a sunny garden",
    "n": 1,
    "size": "1024x1024",
    "quality": "hd"
  }'

5. Audio

Speech recognition and transcription. Transcribe Audio
POST /v1/audio/transcriptions
Request Parameters (Form-Data)
ParameterTypeRequiredDescription
filefileYesAudio file
modelstringYesModel name, e.g., whisper-1
languagestringNoLanguage code
promptstringNoGuidance prompt
response_formatstringNoResponse format
temperaturenumberNoSampling temperature

6. Model List

Get list of available models. Request Endpoint
GET /v1/models
Response Example
{
  "object": "list",
  "data": [
    {
      "id": "gpt-3.5-turbo",
      "object": "model",
      "created": 1677610602,
      "owned_by": "openai"
    },
    {
      "id": "gpt-4o",
      "object": "model",
      "created": 1687882411,
      "owned_by": "openai"
    }
  ]
}

Streaming Responses

Enable Streaming Output

Set stream: true in the request:
{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": true
}

Streaming Response Format

Response will be returned in Server-Sent Events (SSE) format:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1699000000,"model":"gpt-3.5-turbo","choices":[{"delta":{"content":"Hello"},"index":0}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1699000000,"model":"gpt-3.5-turbo","choices":[{"delta":{"content":" there"},"index":0}]}

data: [DONE]

Handling Streaming Responses

  • Python
  • JavaScript
import requests
import json

response = requests.post(
    'https://api.laozhang.ai/v1/chat/completions',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'model': 'gpt-3.5-turbo',
        'messages': [{'role': 'user', 'content': 'Hello'}],
        'stream': True
    },
    stream=True
)

for line in response.iter_lines():
    if line:
        line = line.decode('utf-8')
        if line.startswith('data: '):
            data = line[6:]
            if data != '[DONE]':
                chunk = json.loads(data)
                content = chunk['choices'][0]['delta'].get('content', '')
                print(content, end='')

Error Handling

Error Response Format

{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

Common Error Codes

Error CodeHTTP StatusDescription
invalid_api_key401Invalid API key
insufficient_quota429Insufficient quota
model_not_found404Model does not exist
invalid_request_error400Invalid request parameters
server_error500Internal server error
rate_limit_exceeded429Request rate too high

Error Handling Example

try:
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": "Hello"}]
    )
except Exception as e:
    if hasattr(e, 'status_code'):
        if e.status_code == 401:
            print("Invalid API key")
        elif e.status_code == 429:
            print("Requests too frequent or insufficient quota")
        elif e.status_code == 500:
            print("Server error, please try again later")
    else:
        print(f"Unknown error: {str(e)}")

Best Practices

1. Request Optimization

  • Set max_tokens reasonably: Avoid unnecessarily long outputs
  • Use temperature: Control output randomness
  • Batch processing: Combine multiple requests to reduce call count

2. Error Retry

Implement exponential backoff retry mechanism:
import time
import random

def retry_with_backoff(func, max_retries=3):
    for i in range(max_retries):
        try:
            return func()
        except Exception as e:
            if i == max_retries - 1:
                raise e
            wait_time = (2 ** i) + random.uniform(0, 1)
            time.sleep(wait_time)

3. Security Recommendations

  • Protect API keys: Store in environment variables
  • Limit permissions: Create different keys for different applications
  • Monitor usage: Regularly check API usage logs

4. Performance Optimization

  • Use streaming output: Improve user experience
  • Cache responses: Cache results for identical requests
  • Concurrency control: Reasonably control concurrent request count

Rate Limits

LaoZhang API implements the following rate limits:
Limit TypeLimit ValueDescription
RPM (Requests Per Minute)3000Per API key
TPM (Tokens Per Minute)1000000Per API key
Concurrent Requests100Simultaneously processed requests
429 error will be returned when limits are exceeded. Please control request frequency reasonably.

Need Help?

This manual is continuously updated. Please follow the latest version for new features and improvements.
I