Using Official OpenAI SDKs
LaoZhang API is fully compatible with OpenAI API format. You can use official OpenAI SDKs directly with minimal configuration changes.Use
https://api2.laozhang.ai/v1 as the default base_url. Europe/US servers can use the direct overseas route https://api-vip.laozhang.ai/v1. The global Cloudflare fallback is https://api-cf.laozhang.ai/v1; long-running synchronous requests should account for the approximately 120-second proxy read timeout. See the API domain selection and migration notice.Supported Official SDKs
LaoZhang API supports all official OpenAI SDKs:- Python (
openai) - Node.js (
openai) - .NET (
OpenAI) - Go (
go-openai) - Java (third-party)
- PHP (third-party)
- Ruby (third-party)
Python SDK
Installation
Basic Configuration
Environment Variable Configuration
Async Usage
Streaming Output
Node.js SDK
Installation
Basic Configuration
Environment Variable Configuration
Streaming Output
TypeScript Support
.NET SDK
Installation
Basic Configuration
Streaming Output
Go SDK
Installation
Basic Configuration
Model Switching
Using Different Models
Dynamic Model Selection
Advanced Features
Function Calling
Image Input
Embeddings
Error Handling
Basic Error Handling
Detailed Error Handling
Best Practices
1. Configuration Management
2. Retry Mechanism
3. Cost Control
Migration Guide
Migrating from OpenAI
If you’re already using official OpenAI services, migrating to LaoZhang API is straightforward:- Change base_url
- Update Environment Variables
- No Code Changes Required All other code remains unchanged, including:
- Method calls
- Parameter formats
- Response handling