DEV Community

ChinaWHAPI Team
ChinaWHAPI Team

Posted on

Getting Started with ChinaWHAPI: Access DeepSeek, Qwen, and More with OpenAI-Compatible SDKs

Introduction

ChinaWHAPI provides a unified, OpenAI-compatible API gateway to access leading Chinese Large Language Models (LLMs) including DeepSeek, Qwen, GLM, and more. This guide will help you get started with ChinaWHAPI in just a few minutes.

Why Choose ChinaWHAPI?

Key Benefits

  • Unified API: One endpoint for multiple Chinese LLM providers
  • OpenAI-Compatible: Use existing OpenAI SDKs without code changes
  • Cost-Effective: Access high-quality Chinese models at competitive prices
  • Reliable: Enterprise-grade infrastructure with 99.9% uptime SLA
  • Fast: Optimized routing and caching for minimal latency

Available Models

Model Provider Context Window Price (per 1M tokens)
DeepSeek-V3 DeepSeek 64K ¥1.33 (input) / ¥5.32 (output)
Qwen-Max Alibaba 32K ¥2.5 / ¥7.5
GLM-Edge Zhipu AI 128K ¥1 / ¥3
HunYuan Tencent 128K ¥1 / ¥4

Quick Start Guide

Step 1: Get Your API Key

  1. Visit ChinaWHAPI and create an account
  2. Navigate to the API Keys section in your dashboard
  3. Generate a new API key and copy it securely

Step 2: Install the SDK

Choose your preferred programming language:

Python:

pip install openai
Enter fullscreen mode Exit fullscreen mode

Node.js:

npm install openai
Enter fullscreen mode Exit fullscreen mode

Step 3: Make Your First API Call

Python Example:

from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="https://api.chinawhapi.com/v1"
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello, how are you?"}
    ],
    temperature=0.7,
    max_tokens=1000
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Node.js Example:

const OpenAI = require('openai');

const client = new OpenAI({
    apiKey: 'your-api-key',
    baseURL: 'https://api.chinawhapi.com/v1'
});

async function main() {
    const response = await client.chat.completions.create({
        model: 'deepseek-chat',
        messages: [
            { role: 'system', content: 'You are a helpful assistant.' },
            { role: 'user', content: 'Hello, how are you?' }
        ],
        temperature: 0.7,
        max_tokens: 1000
    });

    console.log(response.choices[0].message.content);
}

main();
Enter fullscreen mode Exit fullscreen mode

Advanced Features

Streaming Responses

ChinaWHAPI supports streaming for real-time token generation:

Python:

stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Write a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
Enter fullscreen mode Exit fullscreen mode

Function Calling

Leverage advanced function calling capabilities:


python
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="d
Enter fullscreen mode Exit fullscreen mode

Top comments (0)