Skip to content

Chat Completion

Chat completions are the core of the Exnest AI SDK. They allow you to generate responses from AI models based on a series of messages.

const response = await client.chat.completions.create({
model: 'gpt-4',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Who won the world series in 2020?' },
],
});
console.log(response.choices[0].message.content);
Terminal window
curl -X POST https://api.exnest.app/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "moonshot-v1-8k",
"messages": [
{"role": "user", "content": "jelaskan negara china"}
],
"temperature": 0.7,
"maxTokens": 1000,
"stream": false,
"timeout": 100000,
"exnest_metadata": true
}'