Skip to content

OpenAI 对话格式(Chat Completions)

简介

给定一组包含对话的消息列表,模型将返回一个响应。相关指南可参阅OpenAI官网:Chat Completions

基础文本

js
curl https://api.nextaicore.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "你好!"
      }
    ]
  }'

流式响应

js
curl https://api.nextaicore.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "你好!"
      }
    ],
    "stream": true
  }'

图像生成

js
curl https://api.nextai.trade/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "sora_image",
    "messages": [
      {
        "role": "user",
        "content": "画一只小狗。"
      }
    ],
    "stream": true
  }'

图像分析

js
curl https://api.nextaicore.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "这张图片里有什么?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://example.com/image.jpg"
            }
          }
        ]
      }
    ]
  }'