Appearance
API 示例
最小流式测试
bash
curl -N https://api.xai.kg/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{ "role": "user", "content": "Reply exactly: pong" }
],
"stream": true
}'1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Node.js
js
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.XAI_KG_API_KEY,
baseURL: 'https://api.xai.kg/v1'
})
const stream = await client.chat.completions.create({
model: 'gpt-5.5',
messages: [{ role: 'user', content: '写一个短标题' }],
stream: true
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '')
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16