Skip to main content

Chat Completion

Create chat completion​

path=/chat/completions method=post

Request

JavaScript

const { OpenAI } = require('openai');

const api = new OpenAI({
baseURL: 'https://api.umamiai.xyz/v1',
apiKey: '<YOUR_UMAMIAI_API_KEY>',
});

const main = async () => {
const result = await api.chat.completions.create({
model: 'super',
messages: [
{
role: 'system',
content: 'You are an AI assistant who knows everything.',
},
{
role: 'user',
content: 'Tell me, why is the sky blue?'
}
],
});

const message = result.choices[0].message.content;
console.log(`Assistant: ${message}`);
};

main();

Python

import os
from openai import OpenAI

client = OpenAI(
base_url="https://api.umamiai.xyz/v1",
api_key="<YOUR_UMAMIAI_API_KEY>",
)

response = client.chat.completions.create(
model="super",
messages=[
{
"role": "system",
"content": "You are an AI assistant who knows everything.",
},
{
"role": "user",
"content": "Tell me, why is the sky blue?"
},
],
)

message = response.choices[0].message.content

print(f"Assistant: {message}")

Curl

curl -L \
-X POST \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
-H 'Content-Type: application/json' \
'https://api.umamiai.xyz/v1/chat/completions' \
-d '{"model":"text","messages":[{
"role": "system",
"content": "You are an AI assistant who knows everything.",
},
{
"role": "user",
"content": "Tell me, why is the sky blue?"
},]}'

Code Completion Example​

JavaScript

const { OpenAI } = require('openai');

const api = new OpenAI({
baseURL: 'https://api.umamiai.xyz/v1',
apiKey: '<YOUR_UMAMIAI_API_KEY>',
});

const main = async () => {

const result = await api.chat.completions.create({
model: 'codellama/CodeLlama-70b-Instruct-hf',
messages: [
{
role: 'system',
content: 'You are an AI assistant who knows everything.',
},
{
role: 'user',
content: 'Tell me, why is the sky blue?'
}
],
});

const message = result.choices[0].message.content;
console.log(`Assistant: ${message}`);
};

main();

Python

import os
from openai import OpenAI

client = OpenAI(
api_key="<YOUR_UMAMIAI_API_KEY>",
base_url="https://api.umamiai.xyz/v1",
)

response = client.chat.completions.create(
model="codellama/CodeLlama-70b-Instruct-hf",
messages=[
{
"role": "system",
"content": "You are an AI assistant who knows everything.",
},
{
"role": "user",
"content": "Tell me, why is the sky blue?"
},
],
)

message = response.choices[0].message.content
print(f"Assistant: {message}")

Vision & Chat Completion Example​

JavaScript

const main = async () => {
const result = await fetch('https://api.umamiai.xyz/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: 'Bearer <YOUR_UMAMIAI_API_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo',
max_tokens: 1024,
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'What’s in this image?',
},
{
role: 'user',
type: 'image_url',
image_url: {
url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg',
},
},
],
},
],
}),
}).then((res) => res.json());

const message = result.choices[0].message.content;
console.log(`Assistant: ${message}`);
};

main();

Python

import os
from together import Together

client = Together(base_url="https://api.umamiai.xyz/v1", api_key="<YOUR_UMAMIAI_API_KEY>")

def main():
response = client.chat.completions.create(
model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "What sort of animal is in this picture? What is its usual diet? What area is the animal native to? And isn’t there some AI model that’s related to the image?",
},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/LLama.jpg/444px-LLama.jpg?20050123205659",
},
},
],
}
],
max_tokens=1024,
)

print("Assistant: ", response.choices[0].message.content)

if __name__ == '__main__':
main()