文本生成
Grok 适合生成、总结、改写、分类、抽取、实时信息问答和多轮对话。接入时优先使用 Responses API:
text
https://xikapi.com/v1/responses基础文本生成
bash
curl https://xikapi.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XIKAPI_API_KEY" \
-d '{
"model": "grok-4.3-latest",
"input": [
{
"role": "user",
"content": "Write a product description in fewer than 100 words"
}
]
}'长文本总结
长文本总结适合合同、会议纪要、报告、客服记录和知识库文档。
json
{
"model": "grok-4.3-latest",
"max_output_tokens": 1200,
"input": [
{
"role": "system",
"content": "You are a document summarization assistant. Preserve key facts, amounts, dates, responsible parties, and risks."
},
{
"role": "user",
"content": "Summarize the following contract content: ..."
}
]
}改写与润色
改写任务建议明确目标语气、长度和保留信息。
text
Rewrite the following support reply to be more polite and clear. Preserve the refund rules and processing timeline, and do not promise anything not stated.分类与抽取
分类和抽取适合客服工单、反馈归因、内容审核、订单备注识别等场景。
json
{
"model": "grok-4.3-latest",
"temperature": 0,
"max_output_tokens": 500,
"input": [
{
"role": "user",
"content": "Classify the text as complaint, inquiry, or praise. Text: I paid, but the order has not arrived."
}
]
}多轮问答
多轮问答可以由服务端维护完整历史,也可以使用 previous_response_id 继续上一轮响应。
json
{
"model": "grok-4.3-latest",
"previous_response_id": "resp_xxx",
"input": [
{ "role": "user", "content": "Continue explaining the second point" }
]
}控制输出长度
可以同时用 max_output_tokens 和提示词约束输出长度。
text
Answer in no more than five bullet points, each under 30 words.生产环境建议:
- 短回复使用较小
max_output_tokens - 总结和分析任务给足输出空间
- 对必须短输出的场景增加服务端截断或校验
控制语气和格式
把稳定要求放在 system 消息中,把本轮任务放在 user 消息中。
json
{
"model": "grok-4.3-latest",
"input": [
{
"role": "system",
"content": "You are an enterprise support assistant. Be polite and concise, and do not invent policies."
},
{
"role": "user",
"content": "The user says a top-up has not arrived. Draft a support reply."
}
]
}常见 Prompt 模板
实时问答:
text
Search for the latest information first, then summarize the conclusion concisely. Include sources and dates.合同总结:
text
Summarize the contract using this structure:
- Parties
- Scope of services
- Payment terms
- Breach liability
- Risks requiring manual review字段抽取:
text
Extract name, phone number, order ID, and issue type from the text. Use null for unknown fields.最佳实践
- 把稳定角色和边界放入 system 消息
- 对分类、抽取等任务降低
temperature - 输出 JSON 时配合服务端解析和校验
- 需要最新信息时启用搜索工具
- 不要把 API Key 暴露在浏览器前端