AI Models
Chat Completions
Generate conversational responses with AI models
Chat Completions API
The Chat Completions API enables you to generate conversational responses from AI models. It supports multi-turn conversations, system prompts, and various output formats.
Basic Usage
const response = await fetch('https://api.llm.catlove.cc/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' }
],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);Streaming
For real-time responses, enable streaming:
const response = await fetch('https://api.llm.catlove.cc/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
}),
});
const reader = response.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Process streaming chunks
}