API Documentation

Use the Doubao API to integrate text generation, embeddings, and image workflows into your own applications, services, or internal tools.

Base URL: https://api.doubao-ai.com/v1

Authentication

All requests must include an API key in the Authorization header. Requests without valid credentials should be rejected before endpoint processing begins.

Authorization: Bearer YOUR_API_KEY

Error Codes

API responses should be checked for HTTP status, structured error output, and request context. Applications are easier to maintain when client-side retry, validation, and logging behavior are handled explicitly.

Status Meaning Typical Handling
400 Bad Request Check payload structure, parameter types, and required fields
401 Unauthorized Check API key validity and header formatting
429 Rate Limited Retry with backoff and review request volume
500 Server Error Retry where appropriate and log the failure context

Chat Completions

Create a completion from a message sequence for single-turn or multi-turn conversational workflows.

Request Parameters

Parameter Type Required Description
model string Yes Model identifier, such as doubao-pro-v1
messages array Yes Ordered message list containing prior conversation turns
temperature float No Sampling temperature between 0 and 2; typical default is 0.7

Example Code

curl https://api.doubao-ai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DB_API_KEY" \
  -d '{
    "model": "doubao-pro-v1",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'
import os
from doubao import DoubaoClient

client = DoubaoClient(api_key=os.environ.get("DB_API_KEY"))

completion = client.chat.completions.create(
  model="doubao-pro-v1",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message.content)
import Doubao from "doubao-ai";

const doubao = new Doubao({ apiKey: process.env.DB_API_KEY });

const completion = await doubao.chat.completions.create({
  model: "doubao-pro-v1",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello!" }
  ]
});

console.log(completion.choices[0].message.content);

Embeddings

Create vector representations for retrieval, ranking, clustering, or semantic matching workflows.

Parameter Type Required Description
model string Yes Embedding model identifier
input string / array Yes Input text or list of strings to encode

Image Generation

Generate images from text prompts for visual creation, concept drafts, or downstream review workflows.

Request Parameters

Parameter Type Required Description
prompt string Yes Text description of the requested image
size string No Requested image size, such as 1024x1024
curl https://api.doubao-ai.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DB_API_KEY" \
  -d '{
    "prompt": "A futuristic city skyline at sunset",
    "size": "1024x1024"
  }'

Image Editing

Edit or refine existing images by combining uploaded source material with new prompt instructions where supported.