Doubao API Complete Guide: ByteDance's Ultra-Low Cost AI
Introduction
Doubao is ByteDance's AI model offering the lowest pricing in the industry at $0.08/1M input tokens. Through AI API Hub, you can access all Doubao models via the standard OpenAI-compatible API.
Doubao Models
| Model | Input | Output | Best For | |---|---|---|---| | Doubao Pro 1.5 | $0.15/1M | $0.60/1M | Production quality | | Doubao Lite 1.5 | $0.08/1M | $0.32/1M | Cost-sensitive, high volume | | Doubao Vision | $0.15/1M | $0.60/1M | Image understanding |
Python Setup
import openai
client = openai.OpenAI(
api_key="your-api-key",
base_url="https://api.apiyihe.org/v1"
)
response = client.chat.completions.create(
model="doubao-pro-1.5",
messages=[{"role": "user", "content": "Explain cloud computing"}],
max_tokens=1000
)
print(response.choices[0].message.content)
Bulk Processing at Scale
Doubao Lite is ideal for batch processing thousands of documents:
documents = [
"Document about AI trends...",
"Document about blockchain...",
# ... thousands more
]
results = []
for i, doc in enumerate(documents):
r = client.chat.completions.create(
model="doubao-lite-1.5",
messages=[{"role": "user", "content": f"Summarize: {doc}"}],
max_tokens=200
)
results.append(r.choices[0].message.content)
if i % 100 == 0:
print(f"Processed {i}/{len(documents)}")
# Cost: ~$0.02 for summarizing 1000 documents
Streaming
stream = client.chat.completions.create(
model="doubao-pro-1.5",
messages=[{"role": "user", "content": "Tell me about ByteDance"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Node.js
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "your-api-key", baseURL: "https://api.apiyihe.org/v1" });
const r = await client.chat.completions.create({ model: "doubao-lite-1.5", messages: [{ role: "user", content: "Hello Doubao!" }] });
console.log(r.choices[0].message.content);
Cost Comparison
| Task | Doubao Lite | GPT-4o Mini | Savings | |---|---|---|---| | 1000 summaries | $0.02 | $0.10 | 80% | | 10K chat messages | $0.50 | $2.50 | 80% | | 100K translations | $4.00 | $10.00 | 60% |
FAQ
Q: Is Doubao good for production? A: Doubao Pro 1.5 offers production quality at a fraction of GPT-4o pricing.
Q: Does Doubao support function calling? A: Yes, through the OpenAI-compatible API format.
Q: What languages does Doubao support? A: Chinese (native quality), English, and major world languages.