5 分钟接入 3 大国产模型:OpenAI 兼容网关 API Hub 使用指南
2026/8/4 21:50:30 网站建设 项目流程

适合读者

- 会写 OpenAI SDK 的 Python/Node/Java/Go 开发者

- 想快速试国产模型但不想学新 SDK

- 需要国内支付方式的开发者

#### 目录

1. 注册与获取 Key

2. Python 多模型调用示例

3. 流式输出(SSE)配置

4. Function Calling 实战

5. 多模态调用(图片理解)

6. 常用模型推荐与价格参考

#### 1. 注册与获取 Ke

打开 → 注册 → 邮箱验证 → Dashboard 创建 API Key。

**注意:Key 只显示一次,请立即保存!**

#### 2. Python 多模型调用

```python

from openai import OpenAI

client = OpenAI(

api_key="你的APIKey",

base_url="https://apihub4u.com/v1")

# ======== 4 种模型一键切换 ========

# 通用对话 — DeepSeek

print(client.chat.completions.create(

model="deepseek-chat",

messages=[{"role": "user", "content": "介绍一下Python装饰器"}]

).choices[0].message.content)

# 高速低价 — 通义 Turbo

print(client.chat.completions.create(

model="qwen-turbo",

messages=[{"role": "user", "content": "写一首关于夏天的诗"}]

).choices[0].message.content)

# 永久免费 — GLM-4-Flash

print(client.chat.completions.create(

model="glm-4-flash",

messages=[{"role": "user", "content": "今天的日期是什么"}]

).choices[0].message.content)

# 推理编程 — DeepSeek Reasoner

print(client.chat.completions.create(

model="deepseek-reasoner",

messages=[{"role": "user", "content": "用Python写一个快速排序"}]

).choices[0].message.content)

#### 3. 流式输出

```python

stream = client.chat.completions.create(

model="deepseek-chat",

messages=[{"role": "user", "content": "讲个故事"}],

stream=True)

for chunk in stream:

if chunk.choices[0].delta.content:

print(chunk.choices[0].delta.content, end="", flush=True)

#### 4. Function Calling

```python

tools = [{

"type": "function",

"function": {

"name": "get_weather",

"description": "获取指定城市的天气",

"parameters": {

"type": "object",

"properties": {

"city": {"type": "string", "description": "城市名称"}

},

"required": ["city"]

}

}

}]

response = client.chat.completions.create(

model="qwen-plus",

messages=[{"role": "user", "content": "北京今天天气怎么样"}],

tools=tools,

tool_choice="auto")

print(response.choices[0].message.tool_calls)

#### 5. 图片理解(Vision)

```python

response = client.chat.completions.create(

model="qwen-vl-plus",

messages=[{

"role": "user",

"content": [

{"type": "text", "text": "这张图片里有什么"},

{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}

]

}]

)

#### 6. 模型推荐与价格

| 场景 | 推荐模型 | 价格(每百万 Token) |

|------|---------|-------------------|

| 日常对话 | glm-4-flash | **免费** |

| 高速对话 | qwen-turbo | $0.10 |

| 长文处理 | qwen-long | $0.28(10M 上下文) |

| 代码生成 | qwen-coder-plus | $1.19 |

| 深度推理 | deepseek-reasoner | $0.33 |

| 最强对话 | qwen3-max | $1.42 |

| 图片理解 | qwen-vl-plus | $0.32 |

#### 总结

API Hub 让国产模型的接入成本降到和 OpenAI 一样低——你唯一需要做的就是从注册到第一个 API 调用这 5 分钟。

有问题评论区留言,看到就回。

### 配图建议

1. 每个代码块的运行结果截图

2. Dashboard 操作流程 GIF

3. 模型选择器截图

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询