Skip to main content

Anthropic

Features​

  • Text completions: Build advanced chat bots or text processors
  • Function Calling: Utilize tools for specific tasks and API calling.
  • Vision Tasks: Process and analyze images.

Example Requests​

Send a message to the model.​

Pushes a message to the model, allowing interaction or response generation in the context of an AI model.

path=/messages method=post

Request

JavaScript

const response = await fetch('https://api.umamiai.xyz/v1/messages', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY"
},
body: JSON.stringify({
"model": "claude-3-5-sonnet-20240620",
"messages": [
{
"role": "user",
"content": "text"
}
]
}),
});
const data = await response.json();

Python

import requests

response = requests.post(
"https://api.umamiai.xyz/v1/messages",
headers={"Content-Type":"application/json","Authorization": "Bearer YOUR_UMAMIAI_API_KEY"},
json={"model":"claude-3-5-sonnet-20240620","messages":[{"role":"user","content":"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/messages' \
-d '{"model":"claude-3-5-sonnet-20240620","messages":[{"role":"user","content":"text"}]}'

Response

{
"model": "claude-3-5-sonnet-20240620",
"messages": [
{
"role": "user",
"content": "text"
}
],
"max_tokens": 512,
"stop_sequences": [
"text"
],
"stream": false,
"system": "text",
"temperature": 1,
"tool_choice": {
"type": "auto"
},
"tools": [
{
"name": "text",
"description": "text",
"input_schema": {
"type": "object"
}
}
],
"top_k": 0,
"top_p": 0
}

Function Calling​

To process text and use function calling, follow the examples below:

Example Request 1: Get Weather Information​

import requests

url = "https://api.umamiai.xyz/v1/messages"
headers = {
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
}
}
],
"messages": [
{
"role": "user",
"content": "What is the weather like in San Francisco?"
}
],
"stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Example Request 2: Simple Text Response​

import requests

url = "https://api.umamiai.xyz/v1/messages"
headers = {
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "How are you?"
}
],
"stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Pro tip: you can assign a system role to the Claude models by using "system" parameter outside of messages array.

{
model="claude-3-5-sonnet-20240620",
max_tokens=2048,
system="You are a seasoned data scientist at a Fortune 500 company.", # <-- role prompt
messages=[
{"role": "user", "content": "Analyze this dataset for anomalies: <dataset>{{DATASET}}</dataset>"}
]
}

Example Response​

The responses from the UmamiAI API for Anthropic models will typically include the generated text or results from the tool called. Here is an example response for a weather query:

{
"id": "msg-12345",
"object": "message",
"created": 1627684940,
"model": "claude-3-5-sonnet-20240620",
"choices": [
{
"message": {
"role": "assistant",
"content": "The weather in San Francisco is currently sunny with a temperature of 68°F."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 15,
"total_tokens": 25
}
}

Streaming with Python SDK​

To enable streaming of responses, set stream=True in your request payload.

import requests

url = "https://api.umamiai.xyz/v1/messages"
headers = {
"Authorization": "Bearer YOUR_UMAMIAI_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
}
}
],
"messages": [
{
"role": "user",
"content": "What is the weather like in San Francisco?"
}
]