跳转到主要内容
PRODUCT DOCUMENTS

快速找到所需文档,高效完成接入与排障

浏览产品文档与友盟 Skill,展开目录并阅读正文。

cURL

1) 非流式聊天

curl -X POST "https://ai.umeng.com/api/llm/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "enableThinking": false,
    "messages": [
      {"role": "user", "content": "用一句话介绍牛顿第一定律"}
    ]
  }'

2) 非流式聊天(多轮对话,续接会话)

curl -X POST "https://ai.umeng.com/api/llm/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "sess-your-session-id",
    "model": "auto",
    "enableThinking": false,
    "loadHistory": true,
    "messages": [
      {"role": "user", "content": "继续刚才的话题,详细解释一下"}
    ]
  }'

3) 流式聊天(SSE)

curl -X POST "https://ai.umeng.com/api/llm/chat/stream" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  --no-buffer \
  -d '{
    "model": "auto",
    "enableThinking": false,
    "messages": [
      {"role": "user", "content": "请用 Python 写一个 LRU 缓存"}
    ]
  }'

SSE 事件格式:

event: meta
data: {"session_id":"sess-xxx","model":"qwen-turbo"}

event: delta
data: {"type":"content","delta":"以下"}

event: done
data: {"input_tokens":12,"output_tokens":150,"credits":0.002}

4) 获取模型列表

curl -X POST "https://ai.umeng.com/api/llm/listModels" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

5) 图像生成

curl -X POST "https://ai.umeng.com/api/llm/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-5-0-pro-260628",
    "messages": [
      {"role": "user", "content": "一只在滑雪的柴犬"}
    ],
    "imageParams": {"size": "1024x1024", "quality": "low", "n": 1}
  }'

返回的 content 为 Markdown 图片链接:![生成图片1](https://xxx.oss-cn-beijing.aliyuncs.com/xxx.png?签名参数)

6)视频生成(两步:提交 + 轮询)

# ① 提交任务(约 1 秒返回 request_id)
curl -X POST "https://ai.umeng.com/api/llm/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.5-t2v-preview",
    "messages": [
      {"role": "user", "content": "一只橘猫在窗台上晒太阳"}
    ],
    "videoParams": {"resolution": "480P", "ratio": "16:9", "duration": 5}
  }'

# ② 轮询结果(每 15 秒一次,直到 SUCCEEDED 或 FAILED)
curl -X POST "https://ai.umeng.com/api/llm/chat/video/result" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"requestId": "req-35ae61fb8c2146fb8f38a3c652283551"}'

7)视频生成 · 完整轮询脚本

#!/bin/bash
BASE_URL="https://ai.umeng.com"
API_KEY="YOUR_API_KEY"

# ① 提交任务
RID=$(curl -s -X POST "$BASE_URL/api/llm/chat" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.5-t2v-preview",
    "messages": [{"role": "user", "content": "一只橘猫在窗台上晒太阳"}],
    "videoParams": {"resolution": "480P", "ratio": "16:9", "duration": 5}
  }' | grep -o '"request_id":"[^"]*"' | cut -d'"' -f4)

if [ -z "$RID" ]; then echo "提交失败"; exit 1; fi
echo "任务已提交:$RID"

# ② 轮询(每 15 秒,最多 10 分钟)
for i in $(seq 1 40); do
  RESP=$(curl -s -X POST "$BASE_URL/api/llm/chat/video/result" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"requestId\": \"$RID\"}")
  STATUS=$(echo "$RESP" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
  echo "第 ${i} 次轮询,状态:$STATUS"

  if [ "$STATUS" = "SUCCEEDED" ]; then
    echo "视频地址:"
    echo "$RESP" | grep -o '"video_url":"[^"]*"' | cut -d'"' -f4
    break
  fi
  if [ "$STATUS" = "FAILED" ]; then
    echo "生成失败:$RESP"
    break
  fi
  sleep 15
done