Skip to main content

Managing Assistants & Threads

Overview​

Threads and Messages represent a conversation session between an Assistant and a user. There is no limit to the number of Messages you can store in a Thread. When the size of the Messages exceeds the model's context window, the Thread will smartly truncate messages before fully dropping the least important ones.

API Reference​

Delete an assistant.​

Deletes an assistant, removing it from the system.

path=/assistants/{assistantId} method=delete

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/assistants/{assistantId}', {
method: 'DELETE',
headers: {"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
});
const data = await response.json();

Python

import requests

response = requests.delete(
"https://api.umamiai.xyz/v1/assistants/{assistantId}",
headers={"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
)
data = response.json()

Curl

curl -L \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
-X DELETE \
'https://api.umamiai.xyz/v1/assistants/{assistantId}'

Response

{
"id": "text",
"object": "assistant.deleted",
"deleted": false
}

Create a new assistant.​

Creates a new AI assistant, configuring it to perform tasks based on predefined models and settings.

path=/assistants method=post

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/assistants', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",
},
body: JSON.stringify({
"name": "text",
"description": "text",
"model": "text"
}),
});
const data = await response.json();

Python

import requests

response = requests.post(
"https://api.umamiai.xyz/v1/assistants",
headers={"Content-Type":"application/json","Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
json={"name":"text","description":"text","model":"text"}
)
data = response.json()

Curl

curl -L \
-X POST \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
-H 'Content-Type: application/json' \
'https://api.umamiai.xyz/v1/assistants' \
-d '{"name":"text","description":"text","model":"text"}'

Response

{
"id": "text",
"created_at": 0,
"description": "text",
"instructions": "text",
"model": "text",
"name": "text",
"object": "assistant",
"tools": [],
"response_format": {
"type": "json_schema",
"json_schema": {}
},
"temperature": 0,
"top_p": 0
}

List all available assistants.​

Returns a list of AI assistants that are available, allowing users to view and manage their virtual assistants.

path=/assistants method=get

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/assistants', {
method: 'GET',
headers: {"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
});
const data = await response.json();

Python

import requests

response = requests.get(
"https://api.umamiai.xyz/v1/assistants",
headers={"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
)
data = response.json()

Curl

curl -L \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
'https://api.umamiai.xyz/v1/assistants'

Response

{
"object": "list",
"data": [
{
"id": "text",
"created_at": 0,
"description": "text",
"instructions": "text",
"model": "text",
"name": "text",
"object": "assistant",
"tools": [],
"response_format": {
"type": "json_schema",
"json_schema": {}
},
"temperature": 0,
"top_p": 0
}
]
}

Get details of a specific assistant.​

Retrieves information about a specific assistant, including its current configuration and status.

path=/assistants/{assistantId} method=get

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/assistants/{assistantId}', {
method: 'GET',
headers: {"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
});
const data = await response.json();

Python

import requests

response = requests.get(
"https://api.umamiai.xyz/v1/assistants/{assistantId}",
headers={"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
)
data = response.json()

Curl

curl -L \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
'https://api.umamiai.xyz/v1/assistants/{assistantId}'

Response

{
"object": "list",
"data": [
{
"id": "text",
"created_at": 0,
"description": "text",
"instructions": "text",
"model": "text",
"name": "text",
"object": "assistant",
"tools": [],
"response_format": {
"type": "json_schema",
"json_schema": {}
},
"temperature": 0,
"top_p": 0
}
]
}

Update an assistant’s settings.​

Updates the configuration or settings of an existing assistant.

path=/assistants/{assistantId} method=post

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/assistants/{assistantId}', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",
},
body: JSON.stringify({}),
});
const data = await response.json();

Python

import requests

response = requests.post(
"https://api.umamiai.xyz/v1/assistants/{assistantId}",
headers={"Content-Type":"application/json","Authorization": "Bearer YOUR_UMAMIAI_API_KEY",},
json={}
)
data = response.json()

Curl

curl -L \
-X POST \
-H 'Authorization: Bearer YOUR_UMAMIAI_API_KEY' \
-H 'Content-Type: application/json' \
'https://api.umamiai.xyz/v1/assistants/{assistantId}' \
-d '{}'

Response

{
"id": "text",
"created_at": 0,
"description": "text",
"instructions": "text",
"model": "text",
"name": "text",
"object": "assistant",
"tools": [],
"response_format": {
"type": "json_schema",
"json_schema": {}
},
"temperature": 0,
"top_p": 0
}

Using OpenAI threads with UmamiAI API​

const { OpenAI } = require('openai');
const dotenv = require('dotenv');
const prompts = require('prompts');
const axios = require('axios').default;

dotenv.config({ path: ['.env.default', '.env'], override: true });

const STEP_NAMES = {
CREATE_ASSISTANT: 'createAssistant',
CREATE_THREAD: 'selectAssistant',
RUN_THREAD: 'runThread',
INITIAL: 'initial',
};

const steps = {
[STEP_NAMES.CREATE_ASSISTANT]: async ({ api, vendorByModelId }) => {
const { model, name, instructions, description } = await prompts([
{
type: 'autocomplete',
name: 'model',
message: 'Your assistant model',
choices: Object.entries(vendorByModelId).map(([id, vendor]) => ({
title: id,
value: id,
description: vendor,
})),
},
{
type: 'text',
name: 'name',
message: 'Your assistant name',
},
{
type: 'text',
name: 'instructions',
message: 'Your assistant instructions',
},
{
type: 'text',
name: 'description',
message: 'Your assistant description',
},
]);

await api.beta.assistants.create({
model,
name,
description,
instructions,
});

return { step: 'initial' };
},
[STEP_NAMES.INITIAL]: async ({ api }) => {
const assistants = await api.beta.assistants.list({ order: 'desc' });
const { assistantId } = await prompts({
type: 'select',
name: 'assistantId',
message: 'Select assistant',
choices: [
{ title: 'Create new', value: 'new' },
...assistants.data.map((item) => ({ title: item.name, description: item.model, value: item.id })),
],
});

if (assistantId === 'new') {
return { step: STEP_NAMES.CREATE_ASSISTANT };
}

return { step: STEP_NAMES.CREATE_THREAD, assistantId };
},
[STEP_NAMES.CREATE_THREAD]: async ({ api }) => {
const thread = await api.beta.threads.create({ messages: [] });
return { step: STEP_NAMES.RUN_THREAD, thread };
},

[STEP_NAMES.RUN_THREAD]: async ({ api, assistantId, thread }) => {
const { text } = await prompts([
{
type: 'text',
name: 'text',
message: 'Message',
},
]);

await api.beta.threads.messages.create(thread.id, {
role: 'user',
content: text,
metadata: {
userId: 'example-1',
},
});

await api.beta.threads.runs.createAndPoll(thread.id, { assistant_id: assistantId });
const messages = await api.beta.threads.messages.list(thread.id, { order: 'desc', limit: 1 });
const msg = messages.data[0].content.find((item) => item.type === 'text').text.value;
console.log(`Assistant: ${msg}`);

return { step: STEP_NAMES.RUN_THREAD };
},
};

const main = async () => {
const api = new OpenAI({
baseURL: 'https://api.umamiai.xyz/v1',
apiKey: process.env.API_TOKEN,
});

const vendorByModelId = await axios.get('https://api.umamiai.xyz/v1/models').then((r) => r.data);
let step = 'initial';
let payload = { api, vendorByModelId };
while (step) {
const result = await steps[step](payload);
const { step: nextStep, ...nextPayload } = result ?? {};

payload = { ...payload, ...nextPayload };
step = nextStep;
}
};

main();