import OpenAI from 'openai'; const client = new OpenAI({ baseURL: 'http://localhost:3030/api/v1/ai/chat', apiKey: process.env.GAIA_API_KEY }); const response = await client.chat.completions.create({ chatId: 'chat-123', model: 'gpt-4o', messages: [ { role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'What is RAG?' } ], temperature: 0.7 }); console.log(response.choices[0].message.content);
{ "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "model": "gpt-4o", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "RAG stands for Retrieval-Augmented Generation..." }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 20, "completion_tokens": 100, "total_tokens": 120 } }
OpenAI-compatible chat completion endpoint with streaming support
Show Message Object
system
user
assistant
Show Choice Object
Show Usage Object
stream: true
const stream = await client.chat.completions.create({ chatId: 'chat-123', model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello!' }], stream: true }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ''); }
chatId