跳转到内容

开发对接必看

:electric_plug: 完整功能接口映射表

Section titled “:electric_plug: 完整功能接口映射表”
功能路径完整示例URL
智能对话/v1/chat/completionshttps://api.4allapi.com/v1/chat/completions
Claude格式对话/v1/messageshttps://api.4allapi.com/messages
文本嵌入/v1/embeddingshttps://api.4allapi.com/v1/embeddings
AI绘图/v1/images/generationshttps://api.4allapi.com/v1/images/generations
语音转文本/v1/audio/transcriptionshttps://api.4allapi.com/v1/audio/transcriptions
文本转语音/v1/audio/speechhttps://api.4allapi.com/v1/audio/speech

需要先 pip install openai

复制

import os
from openai import OpenAI
client = OpenAI(
# 若没有配置环境变量,请用您从4All API购买兑换到的API Key(密钥)将下行替换为:api_key="sk-xxx",
api_key=os.getenv("API_KEY"),
base_url="https://api.4allapi.com/v1",
)
completion = client.chat.completions.create(
model="qwen3-max", # 模型名请使用您购买的API Key允许的模型名测试,否则会调不同。4All API部分套餐是全场模型可用,部分是限制部分模型,务必要能和网站内显示的名字完全一致
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你是谁?"},
],
stream=True
)
for chunk in completion:
print(chunk.choices[0].delta.content, end="", flush=True)

++2)curl 示例(Linux、Mac操作系统)++

Section titled “++2)curl 示例(Linux、Mac操作系统)++”

复制以下命令替换里面的key, 然后粘贴到操作系统的终端中执行

Terminal window
curl --request POST \
--url https://api.4allapi.com/v1/chat/completions \
--header 'Authorization: Bearer sk-替换为你的key' \
-H "Content-Type: application/json" \
--data '{
"model": "qwen-plus",
"messages": [
{
"role": "user",
"content": "你好"
}
]
}'

++3)curl 示例(Windows操作系统)++

Section titled “++3)curl 示例(Windows操作系统)++”

复制以下命令替换里面的key, 然后粘贴到CMD或者powershell终端中执行

Terminal window
curl https://api.4allapi.com/v1/chat/completions ^
-H "Content-Type: application/json" ^
-H "Authorization: Bearer sk-替换为你的key" ^
-d "{\"model\": \"qwen-plus\", \"messages\": [{\"role\": \"user\", \"content\": \"你好\"}]}"

请看官方API文档: https://4allapi.apifox.cn


4All API · 一站式AI大模型API聚合平台 | 价格 | 联系我们

© 2025 4All API. All rights reserved.