GPT 6 Astra API
由 OpenAI 提供的 GPT 6 Astra 大语言模型的完整 API 参考文档。
模型类型
此 API 支持四种模型:
快速对比
GPT 6 Astra Text to Text
端点
POST /api/v1/chat/completions
请求参数
必填
消息支持
可选
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-6-astra-text-to-text',
messages: [
{
role: 'user',
content: 'Write a short launch announcement for a new AI feature.'
}
],
stream: true,
max_tokens: 2048
})
});
GPT 6 Astra Image to Text
端点
POST /api/v1/chat/completions
请求参数
必填
消息支持
可选
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-6-astra-image-to-text',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe the image and extract any visible text.' },
{
type: 'image_url',
image_url: {
url: 'https://example.com/sample-image.jpg'
}
}
]
}
],
stream: true,
max_tokens: 2048
})
});
GPT 6 Astra Web Search
端点
POST /api/v1/chat/completions
请求参数
必填
消息支持
可选
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-6-astra-web-search',
messages: [
{
role: 'user',
content: 'Find recent product launch trends in AI developer tools.'
}
],
stream: true,
max_tokens: 2048
})
});
GPT 6 Astra File Analysis
端点
POST /api/v1/chat/completions
请求参数
必填
消息支持
可选
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-6-astra-file-analysis',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize this document and list the key action items.' },
{
type: 'file',
file: {
filename: 'demo.pdf',
file_data: 'https://example.com/demo.pdf'
}
}
]
}
],
stream: true,
max_tokens: 2048
})
});
响应格式
GPT 6 Astra 大语言模型返回与 OpenAI 兼容的生成响应。设置 stream: true 时,响应为服务器发送事件(SSE);设置 stream: false 时,响应为单个 JSON 对象。
成功响应
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gpt-6-astra-image-to-text","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gpt-6-astra-image-to-text","choices":[{"index":0,"delta":{"content":"The image shows"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gpt-6-astra-image-to-text","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gpt-6-astra-image-to-text","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
错误响应
event: error
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
最佳实践
- 保持消息结构化: 使用
messages[] 传递对话历史,不要将上下文合并为一个提示词。
- 将文件和图像附加到消息中: 将
image_url 和 file 内容部分放入引入相应文件或图像的消息内。
- 使用 SSE 解析: 追加
choices[0].delta.content 以增量显示内容,并将 data: [DONE] 视为成功完成。
- 仅发送支持的输入: 文本、图像和文件内容部分应与所选模型的支持范围一致。
- 在本地存储请求状态: 数据块包含生成响应的
id,但客户端仍应通过当前活动请求的状态将数据块分发至对应处理流程。