豆包是字节跳动推出的大语言模型服务,提供 Doubao 系列模型的 API 访问。通过火山引擎平台调用,兼容 OpenAI API 格式。以极低价格和中文理解能力著称,Doubao-Pro 价格仅为同级别模型的十分之一。
通过火山引擎 API Key 认证:
Authorization: Bearer xxxxxxxxxx
API Key 在 火山引擎方舟控制台 创建。
OpenAI兼容格式:https://ark.cn-beijing.volces.com/api/v3
| 模型ID | 上下文 | 最大输出 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| doubao-1.5-pro-256k | 256K | 16K | 旗舰模型,超长上下文 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-pro-32k | 32K | 8K | 旗舰模型,标准版 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-lite-32k | 32K | 8K | 轻量模型,高性价比 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-vision-pro-32k | 32K | 8K | 多模态旗舰 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-vision-lite-32k | 32K | 4K | 多模态轻量 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-embedding | - | - | 文本嵌入 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from openai import OpenAI
client = OpenAI(
api_key="your-ark-api-key",
base_url="https://ark.cn-beijing.volces.com/api/v3"
)
response = client.chat.completions.create(
model="doubao-1.5-pro-32k",
messages=[
{"role": "system", "content": "你是豆包助手。"},
{"role": "user", "content": "你好!"}
],
temperature=0.7,
max_tokens=2048
)
print(response.choices[0].message.content)
response = client.chat.completions.create(
model="doubao-1.5-pro-32k",
messages=[{"role": "user", "content": "证明根号2是无理数"}],
extra_body={
"thinking": {"type": "enabled"},
"reasoning_effort": "high"
}
)
# 思考过程在 reasoning_content 中
print(response.choices[0].message.reasoning_content)
print(response.choices[0].message.content)
stream = client.chat.completions.create(
model="doubao-1.5-pro-32k",
messages=[{"role": "user", "content": "解释量子计算"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
tools = [{
"type": "function",
"function": {
"name": "search_web",
"description": "搜索互联网信息",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "搜索关键词"}
},
"required": ["query"]
}
}
}]
response = client.chat.completions.create(
model="doubao-1.5-pro-32k",
messages=[{"role": "user", "content": "最新AI新闻"}],
tools=tools,
tool_choice="auto"
)
response = client.chat.completions.create(
model="doubao-1.5-vision-pro-32k",
messages=[{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
{"type": "text", "text": "描述这张图片"}
]
}]
)
| 模型 | 输入价格 | 输出价格 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| doubao-1.5-pro-32k | ¥4/1M tokens | ¥16/1M tokens | 旗舰级性价比 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-pro-256k | ¥8/1M tokens | ¥32/1M tokens | 超长上下文 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-lite-32k | ¥0.5/1M tokens | ¥2/1M tokens | 极低成本 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doubao-1.5-vision-pro | ¥6/1M tokens | ¥24/1M tokens | 多模态 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
新用户赠送 50 万 tokens 免费额度。
| 层级 | RPM | TPM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 免费 | 3 | 40,000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 基础 | 60 | 300,000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 标准 | 300 | 1,000,000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 状态码 | 含义 | 处理 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 400 | 请求格式错误 | 检查参数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 认证失败 | 检查API Key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 权限不足 | 开通模型访问权限 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 速率限制 | 退避重试 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 服务端错误 | 稍后重试 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
评论区