curl --request POST \
--url https://api.altrum.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
'import requests
url = "https://api.altrum.ai/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'openai/gpt-4o-mini', messages: [{role: 'user', content: 'Say hello.'}]})
};
fetch('https://api.altrum.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"id": "chatcmpl-123",
"object": "chat.completion",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 2,
"total_tokens": 11
}
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}Create a chat completion
Sends a conversation to a model in the OpenAI chat format. Any supported provider can answer: the reply comes back in the OpenAI format.
curl --request POST \
--url https://api.altrum.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
'import requests
url = "https://api.altrum.ai/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Say hello."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'openai/gpt-4o-mini', messages: [{role: 'user', content: 'Say hello.'}]})
};
fetch('https://api.altrum.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"id": "chatcmpl-123",
"object": "chat.completion",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 2,
"total_tokens": 11
}
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}{
"type": "budget_exceeded",
"is_gateway_error": true,
"status_code": 402,
"error": {
"type": "budget_exceeded",
"code": "budget_exceeded",
"message": "Budget exceeded: ..."
},
"request_id": "4f9c..."
}Authorizations
Your virtual key, sk-alt-.... What every OpenAI and Anthropic SDK sends.
Headers
Your own reference for the request. Altrum uses it instead of making one, and returns it.
Use a prompt saved in your AI Gateway prompts. Its messages go before yours.
The prompt version to use, such as 2. Without it, the latest version.
Keeps this request's cached answers apart from others, for example per customer.
Keeps the answer for less time than your setting: 30s, 5m, 1h or a number of seconds.
Asks for a closer match than your setting, from 0 to 1.
direct matches word for word only, semantic by meaning only.
direct, semantic true serves from the cache when it can, but does not store this answer.
true true keeps this request's prompt and reply out of the request log, even when your organization keeps content.
true true sends your own provider key in Authorization, x-api-key or x-goog-api-key, with your virtual key in x-alt-vk. Only when your organization allows it.
true Body
An OpenAI chat completion request. Every other field the OpenAI API accepts is passed to the model.
The provider and the model, such as openai/gpt-4o-mini. A name without a provider is matched to one your organization can serve.
"openai/gpt-4o-mini"
The conversation, in the OpenAI chat format.
Stream the answer as server-sent events.
Models to try in order when an attempt fails. Altrum's addition to the request body.
Response
The completion.
An OpenAI chat completion.