Skip to content
byteplus.cc
docs

ドキュメント

ByteDanceのDoubao、Seedance、Seedreamモデルに向けた単一のOpenAI互換サーフェスです。

base_url: https://byteplus.cc/v1
01

クイックスタート

OpenAI SDKはそのまま動作します。変更するのはbase URLとモデルIDだけです。キーはプロジェクト単位でスコープが切られ、ダウンタイムなしでローテーションできます。

  1. 1アカウントを作成し、ダッシュボードでキーを発行します。
  2. 2base URLをhttps://byteplus.cc/v1に設定します。
  3. 3doubao-seed-1-6などのByteDanceのモデルIDを使用します。
quickstart
# any OpenAI-compatible client works
pip install openai
export BYTEPLUS_KEY="bp_live_xxxxxxxxxxxxxxxx"
02

認証

キーはベアラートークンとして送信します。キーのないリクエストは401を返し、クォータを超えたリクエストはretry-afterヘッダー付きで429を返します。

authentication
curl https://byteplus.cc/v1/chat/completions \
  -H "Authorization: Bearer $BYTEPLUS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"doubao-pro-32k","messages":[{"role":"user","content":"hi"}]}'

# 401  invalid_api_key
# 429  rate_limit_exceeded   (see retry-after header)
03

チャット補完

POST /v1/chat/completionsは標準的なOpenAIのペイロード(model、messages、temperature、max_tokens、stream、tools)を受け付けます。

chat
from openai import OpenAI

client = OpenAI(
    base_url="https://byteplus.cc/v1",
    api_key=os.environ["BYTEPLUS_KEY"],
)

stream = client.chat.completions.create(
    model="doubao-seed-1-6",
    messages=[{"role": "user", "content": "Summarise this deck."}],
    temperature=0.7,
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
04

動画タスク

動画は非同期です。タスクを作成し、ポーリングするかwebhookを待ちます。タスクIDは安定しており、結果は24時間取得可能です。

video
# 1. create the task
curl https://byteplus.cc/v1/video/tasks \
  -H "Authorization: Bearer $BYTEPLUS_KEY" \
  -d '{
    "model": "seedance-1-0-pro",
    "prompt": "neon koi in a datacenter, dolly-in",
    "resolution": "1080p",
    "duration": 5
  }'
# => {"id": "task_9f2c", "status": "queued"}

# 2. poll for the artifact
curl https://byteplus.cc/v1/video/tasks/task_9f2c \
  -H "Authorization: Bearer $BYTEPLUS_KEY"
# => {"status": "succeeded", "video_url": "https://..."}
05

画像生成

POST /v1/images/generationsはテキストプロンプトからバッチをレンダリングし、POST /v1/images/editsは既存画像に指示を適用します。

image
curl https://byteplus.cc/v1/images/generations \
  -H "Authorization: Bearer $BYTEPLUS_KEY" \
  -d '{
    "model": "seedream-4-0",
    "prompt": "isometric mint server garden, 4K",
    "size": "4096x4096",
    "n": 4
  }'
06

モデル一覧

GET /v1/modelsは、すべてのモデルIDをそのモダリティ、コンテキストウィンドウ、単価とともに返します。

models
curl https://byteplus.cc/v1/models \
  -H "Authorization: Bearer $BYTEPLUS_KEY"

# => {"data": [
#      {"id": "doubao-seed-1-6", "modality": "language", "context": 262144},
#      {"id": "seedance-1-0-pro", "modality": "video", "max_duration": 10},
#      {"id": "seedream-4-0",    "modality": "image", "max_size": "4096x4096"}
#    ]}
07

エラーコード

エラーはOpenAIのエンベロープを使用します。type、code、message、paramを持つerrorオブジェクトです。429と5xxは指数バックオフで再試行してください。

401invalid_api_keyベアラートークンとキーが有効であることを確認してください。
402insufficient_balanceアカウント残高をチャージしてください。
404model_not_foundGET /v1/modelsでモデルIDを確認してください。
422invalid_requestエラーのparamを確認し、ペイロードを修正してください。
429rate_limit_exceededバックオフして再試行するか、同時実行数を予約してください。
503capacity_unavailableretry-afterの時間経過後に再試行してください。キューの順位はヘッダーに含まれます。
08

レート制限

制限はキー単位およびモデル単位で適用され、1分あたりのリクエスト数と1分あたりのトークン数で表されます。予約のお客様には専用の同時実行プールが提供されます。