Markdown ↗

OHGROK / 接入指南

文本对话

发送消息,获取文本回复。

POST/v1/chat/completions获取 Markdown ↗
本页内容

鉴权

使用 Authorization: Bearer YOUR_API_KEY。所选模型须在该密钥分组内开放;JSON 请求使用 Content-Type: application/json。

参数

字段类型必填说明
modelstring必填已开放模型 ID,例如 grok-4.5。
messagesarray必填包含 role 与 content 的消息对象数组。
streamboolean可选false 返回完整 JSON 响应。

请求示例

cURL
export OHGROK_API_KEY='YOUR_API_KEY'

curl --fail-with-body --silent --show-error \
  'https://api.ohgrok.com/v1/chat/completions' \
  -H "Authorization: Bearer $OHGROK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "grok-4.5",
    "messages": [
      {"role": "user", "content": "Give me three short names for a creative coding project."}
    ],
    "stream": false
  }'

响应结构

从 choices[0].message.content 读取回复;usage(如有)记录 token 用量。额外参数与输入模态因模型而异,本页列出最小文本请求。

结构示例,非真实调用回执
{"choices":[{"index":0,"message":{"role":"assistant","content":"Hello!"},"finish_reason":"stop"}]}

错误处理

结合 HTTP 状态与返回的错误信息排查。鉴权或模型权限错误先检查密钥与分组;额度或限流错误检查余额及上游限制;超时时保留已有任务 ID。