跳转至

开发对接必看

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

功能 路径 完整示例URL
智能对话 /v1/chat/completions https://api.4allapi.com/v1/chat/completions
Claude格式对话 /v1/messages https://api.4allapi.com/messages
文本嵌入 /v1/embeddings https://api.4allapi.com/v1/embeddings
AI绘图 /v1/images/generations https://api.4allapi.com/v1/images/generations
语音转文本 /v1/audio/transcriptions https://api.4allapi.com/v1/audio/transcriptions
文本转语音 /v1/audio/speech https://api.4allapi.com/v1/audio/speech

:test_tube: 快速接通验证

++1) Python 示例++**++

需要先 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操作系统)++

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

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操作系统)++

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

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\": \"你好\"}]}"

:blue_book:完整接入文档

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


4All API 页脚

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

© 2025 4All API. All rights reserved.