Command Palette
Search for a command to run...
Code Examples
Example code for integrating with the Alia API
Basic Chat Completion
Make a simple chat completion request
JavaScript
const response = await fetch('https://api.alia.onl/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer alia_sk_YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'alia-v1',
messages: [
{ role: 'user', content: 'Hello!' }
],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);Streaming Response
Stream responses for real-time output
Streaming Example
const response = await fetch('https://api.alia.onl/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer alia_sk_YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'alia-v1',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true,
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n').filter(line => line.startsWith('data: '));
for (const line of lines) {
const data = JSON.parse(line.slice(6));
if (data.choices[0].delta.content) {
process.stdout.write(data.choices[0].delta.content);
}
}
}Function Calling
Define custom tools and let the model call them
Function Calling
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'alia_sk_YOUR_API_KEY',
baseURL: 'https://api.alia.onl/v1',
});
const tools = [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather in a location',
parameters: {
type: 'object',
properties: {
location: { type: 'string', description: 'City and country' },
unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
},
required: ['location']
}
}
}
];
const completion = await openai.chat.completions.create({
model: 'alia-v1',
messages: [{ role: 'user', content: 'What is the weather in Madrid?' }],
tools,
tool_choice: 'auto',
});
console.log(completion.choices[0].message.tool_calls);Agent Configuration
Build intelligent agents with custom tools and instructions
Weather Assistant
Instructions
You are a helpful weather assistant. When the user asks about the weather, use the get_weather tool to fetch current conditions. Always be friendly and provide helpful weather-related advice.
Tools