SurgeAI
  1. openai-format
SurgeAI
  • SurgeAI
    • SurgeAI核心优势
    • 快速开始
    • 认证
    • 如何使用
      • OpenClaw
      • Codex
      • 聊天应用
      • Claude Code
      • Dify
    • API参考
      • OpenAI
        • gpt-5
          • official-format
            • gpt-5 (网络搜索 (Response))
            • gpt-5 (文本转文本)
            • gpt-5 (文本转文本)
            • gpt-5 (图像转文本 (Chat))
            • gpt-5 (图像转文本 (Response))
            • gpt-5 (文件分析)
        • gpt-4o
          • official-format
            • gpt-4o (网络搜索 (Response))
            • gpt-4o (文本转文本 (Response))
            • gpt-4o (文本转文本 (Chat))
            • gpt-4o (图像转文本 (Chat))
            • gpt-4o (图像转文本 (Response))
            • gpt-4o (文件分析 (Response))
        • gpt-4.1
          • official-format
            • gpt-4.1 (联网搜索)
            • gpt-4.1 (文本转文本)
            • gpt-4.1 (文本转文本)
            • gpt-4.1 (图像分析)
            • gpt-4.1 (图像分析)
            • gpt-4.1 (文件分析)
      • Vidu
        • viduq3-pro
          • gptproto-format
            • viduq3-pro (Image To Video)
            • viduq3-pro (Text To Video)
        • viduq2-pro
          • gptproto-format
            • viduq2-pro (Image To Video)
            • viduq2-pro (Text To Video)
      • Suno
        • suno-music
          • official-format
            • official-format (查询任务)
            • official-format (文本转音频)
      • Midjourney
        • Midjourney
          • task-submission
            • midjourney (imagine)
          • task-query
            • midjourney (fetchfromtask)
      • Grok
        • grok-3
          • openai-format
            • grok-3 (文本转文本 (聊天))
        • grok-4
          • openai-format
            • grok-4 (文本转文本 (聊天))
      • DeepSeek
        • deepseek-v3.2
          • openai-format
            • deepseek-v3.2 (文本转文本)
      • Alibaba
        • qwen-plus
          • openai-format
            • qwen-plus (文本转文本)
        • qwen3-max
          • openai-format
            • qwen3-max (文本转文本)
        • wan-2.5-preview
          • gptproto-format
            • wan-2.5-preview (图片编辑)
            • wan-2.5-preview (查询任务)
            • wan-2.5-preview (图生视频)
            • wan-2.5-preview (文生图)
            • wan-2.5-preview (文生视频)
        • qwen-turbo
          • openai-format
            • qwen-turbo (文本转文本)
      • MiniMax
        • hailuo-02-pro
          • gptproto-format
            • hailuo-02-pro (图生视频)
            • hailuo-02-pro (文生视频)
      • Kling
        • kling-v2.1-pro
          • gptproto-format
            • kling-v2.1-pro (图生视频)
            • kling-v2.1-pro (文生视频)
        • kling-v3.0-pro
          • gptproto-format
            • kling-v3.0-pro (图生视频)
            • kling-v3.0-pro (文生视频)
      • Claude
        • claude-haiku-4-5-20251001
          • official-format
            • claude-haiku-4-5-20251001 (联网搜索)
            • claude-haiku-4-5-20251001 (文件分析)
            • claude-haiku-4-5-20251001 (文本生成)
          • openai-format
            • claude-haiku-4-5-20251001 (联网搜索)
            • claude-haiku-4-5-20251001 (文件分析)
            • claude-haiku-4-5-20251001 (文本生成)
      • Google
        • gemini-2.5-flash
          • official-format
            • gemini-2.5-flash (联网搜索)
            • gemini-2.5-flash (文件分析)
            • gemini-2.5-flash (文本生成)
            • gemini-2.5-flash (图像理解)
        • gemini-2.5-pro
          • official-format
            • gemini-2.5-pro (联网搜索)
            • gemini-2.5-pro (文件分析)
            • gemini-2.5-pro (文本生成)
            • gemini-2.5-pro (图像理解)
      • Runway
        • runwayml-gen3a_turbo-5
          • official-format
            • official-format (提交视频生成任务)
            • official-format (查询任务)
  1. openai-format

grok-4 (文本转文本 (聊天))

来源: https://docs.surgeai.one/docs/allapi/Grok/grok-4/openai-format/text-to-text-chat
使用 xAI 的 Grok API 进行文本转文本生成(OpenAI 兼容格式)

Grok 文本转文本 API 的 OpenAI 兼容格式。

身份验证#

1.
在 https://surgeai.one 注册 SurgeAI 账户
2.
进入控制面板的 API Keys 部分
3.
生成新的 API key (sk-xxxxx)
4.
复制并安全存储您的 API key

响应示例#

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "I'm Grok, a helpful and maximally truthful AI built by xAI. I'm designed to answer questions, provide information, and tackle problems with a bit of wit and wisdom—think of me as inspired by the Hitchhiker's Guide to the Galaxy and JARVIS from Iron Man. Not omniscient, but I'll do my best. What's on your mind?",
        "role": "assistant"
      }
    }
  ],
  "created": 1770018847,
  "id": "abc",
  "model": "grok-4",
  "object": "chat.completion",
  "system_fingerprint": "fp_dd0aa291c6",
  "usage": {
    "completion_tokens": 196,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 124,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 688,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 679
    },
    "total_tokens": 884
  }
}

核心参数#

参数类型必填默认值范围描述
modelstring是--用于生成补全的模型 ID。Grok 提供多种具有不同功能、性能特点和价格点的模型。
messagesarray是--包含当前对话的消息列表。根据您使用的模型,支持不同的消息类型(模态),如文本、图像和音频。
messages.rolestring是-developer, user, system消息作者的角色。
messages.namestring否--参与者的可选名称。为模型提供信息以区分相同角色的参与者。
messages.contentstring / array是--开发者消息的内容。
messages.content.typestring是-text, image_url内容部分的类型
messages.content.textstring否--文本内容
messages.content.image_urlobject是(如果 type 为 image_url)--图像 URL 内容
messages.content.image_url.urlstring否--图像的 URL

高级参数#

参数类型必填默认值范围描述
max_tokensinteger / null否--补全可生成的 token 数量的上限,包括可见输出 token 和推理 token。
streamboolean否falsetrue, false是否逐步流式返回响应。默认为 false。

错误码#

错误码错误名称描述
401UnauthorizedAPI key 缺失或无效
403Forbidden您的 API key 没有权限访问此资源,或请求操作的余额不足
429Too Many Requests您已超出速率限制
500Internal server error发生内部服务器错误
503Content policy violation由于安全顾虑内容被阻止(实际状态码为 400)
修改于 2026-03-11 06:24:05
上一页
grok-3 (文本转文本 (聊天))
下一页
deepseek-v3.2 (文本转文本)
Built with