curl 调用
基础调用
curl -s "${HEIMA_BASE_URL:-https://api.token.heimatianqi.com/v1}/chat/completions" \
-H "Authorization: Bearer $HEIMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mock-chat",
"messages": [{"role": "user", "content": "你好,请用一句话回复"}]
}'
流式(SSE)
curl -N "${HEIMA_BASE_URL:-https://api.token.heimatianqi.com/v1}/chat/completions" \
-H "Authorization: Bearer $HEIMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mock-chat",
"messages": [{"role": "user", "content": "数到五"}],
"stream": true,
"stream_options": {"include_usage": true}
}'
查看可用模型
curl -s "${HEIMA_BASE_URL:-https://api.token.heimatianqi.com/v1}/models" \
-H "Authorization: Bearer $HEIMA_API_KEY"
流式响应为
text/event-stream,以data: [DONE]结束。请在网络层关闭缓冲(例如 Nginx 的proxy_buffering off;),否则会出现「等模型输出结束才一次性显示」。