Documentation Index
Fetch the complete documentation index at: https://docs.agicto.com/llms.txt
Use this file to discover all available pages before exploring further.
流式输出适合聊天窗口、代码生成、长文本写作和 Agent 工作流。用户可以更早看到结果,应用也能边接收边渲染。
使用场景
代码生成
边生成边展示代码,适合 IDE 和命令行工具。
Agent 任务
将模型输出逐步交给前端、日志或任务编排层。
请求示例
在 OpenAI 兼容格式中,将 stream 设置为 true。
curl https://api.agicto.cn/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"stream": true,
"messages": [
{
"role": "user",
"content": "请写一段 100 字以内的产品介绍。"
}
]
}'
Node.js 示例
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AGICTO_API_KEY,
baseURL: "https://api.agicto.cn/v1"
});
const stream = await client.chat.completions.create({
model: process.env.AGICTO_CHAT_MODEL,
stream: true,
messages: [
{
role: "user",
content: "请用三句话介绍 AGICTO API。"
}
]
});
for await (const chunk of stream) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}
处理建议
- 前端按增量内容追加渲染。
- 后端保留超时和重试策略。
- 日志中不要记录完整 API Key。
- 如果你需要 JSON 严格结构,优先使用非流式请求验证格式。
Chat completions
查看会话模型接口参数。