AiBrary
ChatAiBrary Website
  • Getting Started
    • 👋Welcome to AiBrary Docs
  • 🧑‍🔬Try APIs
  • 🪙All Pricing
  • Chat & Multimodal Features
    • Chat
      • Chat Pricing
      • Multimodal Pricing
  • Audio Features
    • Speech To Text
      • Pricing
    • Text To Speech
      • Pricing
  • Translation Features
    • Automatic Translation
      • Pricing
  • Image Features
    • Image Generation
      • Pricing
    • Object Detection
      • Pricing
    • Image Embedding
      • Pricing
  • OCR Features
    • OCR
      • Pricing
  • Embedding
    • Embedding
      • Pricing
  • Video Features
    • Coming Soon!
Powered by GitBook
  1. Chat & Multimodal Features

Chat

import base64
from aibrary import AiBrary

aibrary = AiBrary()

# Function to encode the image
def encode_file(path):
    with open(path, "rb") as file:
        return base64.b64encode(file.read()).decode("utf-8")

# Getting the base64 string
english_audio_base64 = encode_file("tests/assets/file.mp3")
return aibrary.chat.completions.create(
    model="gpt-4o-audio-preview-2024-10-01@openai",
    modalities=["text", "audio"],
    audio={"voice": "alloy", "format": "wav"},
    messages=[
        {"role": "system", "content": "translate to persian"},
        {
            "role": "user",
            "content": [
                {
                    "type": "input_audio",
                    "input_audio": {"data": english_audio_base64, "format": "mp3"},
                }
            ],
        },
    ],
)
from aibrary import AiBrary
aibrary = AiBrary()

# Function to encode the image
def encode_file(path):
    with open(path, "rb") as file:
        return base64.b64encode(file.read()).decode("utf-8")

# Getting the base64 string
base64_image = encode_file("tests/assets/test-image.jpg")

return aibrary.chat.completions.create(
    model="claude-3-haiku@anthropic",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What is in this image?",
                },
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"},
                },
            ],
        }
    ],
)
aibrary = AiBrary()
aibrary.chat.completions.create(
    model="Llama-3.1-Nemotron-70B-Instruct",
    messages=[
        {"role": "user", "content": "How are you today?"},
        {"role": "assistant", "content": "I'm doing great, thank you!"},
    ],
    stream=True,
)
aibrary = AiBrary()
aibrary.chat.completions.create(
    model="Llama-3.1-Nemotron-70B-Instruct",
    messages=[
        {"role": "user", "content": "How are you today?"},
        {"role": "assistant", "content": "I'm doing great, thank you!"},
    ]
)
PreviousAll PricingNextChat Pricing

Last updated 2 months ago

Completions

post
Authorizations
Body
modelstringRequired
messagesobject[]Required
streamany ofOptional
booleanOptional
or
nullOptional
frequency_penaltyany ofOptional
numberOptional
or
nullOptional
logit_biasany ofOptional
or
nullOptional
logprobany ofOptional
booleanOptional
or
nullOptional
max_tokensany ofOptional
integerOptional
or
nullOptional
nany ofOptional
integerOptional
or
nullOptional
presence_penaltyany ofOptional
numberOptional
or
nullOptional
response_formatany ofOptional
or
nullOptional
seedany ofOptional
integerOptional
or
nullOptional
stopany ofOptional
string[]Optional
or
nullOptional
temperatureany ofOptional
numberOptional
or
nullOptional
tool_choiceany ofOptional
string · enumOptionalPossible values:
or
or
nullOptional
toolsany ofOptional
or
nullOptional
top_logprobany ofOptional
integerOptional
or
nullOptional
top_pany ofOptional
numberOptional
or
nullOptional
userany ofOptional
stringOptional
or
nullOptional
Other propertiesanyOptional
Responses
200
Successful Response
application/json
Responseany of
or
422
Validation Error
application/json
post
POST /v0/chat/completions HTTP/1.1
Host: api.aibrary.dev
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 449

{
  "model": "text",
  "messages": [
    {}
  ],
  "stream": true,
  "frequency_penalty": 1,
  "logit_bias": {
    "ANY_ADDITIONAL_PROPERTY": 1
  },
  "logprob": true,
  "max_tokens": 1,
  "n": 1,
  "presence_penalty": 1,
  "response_format": {
    "type": "text"
  },
  "seed": 1,
  "stop": [
    "text"
  ],
  "temperature": 1,
  "tool_choice": "none",
  "tools": [
    {
      "function": {
        "name": "text",
        "description": "text",
        "parameters": {},
        "strict": true
      },
      "type": "function"
    }
  ],
  "top_logprob": 1,
  "top_p": 1,
  "user": "text",
  "ANY_ADDITIONAL_PROPERTY": "anything"
}
{
  "id": "text",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 1,
      "logprobs": {
        "content": [
          {
            "token": "text",
            "bytes": [
              1
            ],
            "logprob": 1,
            "top_logprobs": [
              {
                "token": "text",
                "bytes": [
                  1
                ],
                "logprob": 1,
                "ANY_ADDITIONAL_PROPERTY": "anything"
              }
            ],
            "ANY_ADDITIONAL_PROPERTY": "anything"
          }
        ],
        "refusal": [
          {
            "token": "text",
            "bytes": [
              1
            ],
            "logprob": 1,
            "top_logprobs": [
              {
                "token": "text",
                "bytes": [
                  1
                ],
                "logprob": 1,
                "ANY_ADDITIONAL_PROPERTY": "anything"
              }
            ],
            "ANY_ADDITIONAL_PROPERTY": "anything"
          }
        ],
        "ANY_ADDITIONAL_PROPERTY": "anything"
      },
      "message": {
        "content": "text",
        "refusal": "text",
        "role": "assistant",
        "function_call": {
          "arguments": "text",
          "name": "text",
          "ANY_ADDITIONAL_PROPERTY": "anything"
        },
        "tool_calls": [
          {
            "id": "text",
            "function": {
              "arguments": "text",
              "name": "text",
              "ANY_ADDITIONAL_PROPERTY": "anything"
            },
            "type": "function",
            "ANY_ADDITIONAL_PROPERTY": "anything"
          }
        ],
        "ANY_ADDITIONAL_PROPERTY": "anything"
      },
      "ANY_ADDITIONAL_PROPERTY": "anything"
    }
  ],
  "created": 1,
  "model": "text",
  "object": "chat.completion",
  "service_tier": "scale",
  "system_fingerprint": "text",
  "usage": {
    "completion_tokens": 1,
    "prompt_tokens": 1,
    "total_tokens": 1,
    "completion_tokens_details": {
      "reasoning_tokens": 1,
      "ANY_ADDITIONAL_PROPERTY": "anything"
    },
    "ANY_ADDITIONAL_PROPERTY": "anything"
  },
  "ANY_ADDITIONAL_PROPERTY": "anything"
}