Skip to main content

Python SDK for the Beaver AI Gateway

Project description

Beaver AI Python SDK v0.2.0

Comprehensive Python SDK for the Beaver AI Gateway. Fully OpenAI-compatible with dot notation access and support for all major endpoints.

Installation

pip install beaver-ai

Quick Start (v0.2.0+)

Initializing the Client

from beaver_ai import Beaver

beaver = Beaver(api_key="your-api-key")
# Defaults to https://api.beaverai.cloud/v1

Chat Completions

Dot notation is now the standard for accessing response data.

Non-Streaming

response = beaver.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=False
)

print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.total_tokens}")

Streaming (Default)

stream = beaver.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a story."}]
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Image Generation

img = beaver.images.generate(
    model="dall-e-3",
    prompt="A futuristic beaver building a dam of fiber optics"
)

print(img.data[0].url)

Embeddings

emb = beaver.embeddings.create(
    model="text-embedding-3-small",
    input="The quick brown fox jumps over the lazy dog"
)

print(f"Dimensions: {len(emb.data[0].embedding)}")

Audio (Text-to-Speech)

audio_bytes = beaver.audio.speech.create(
    model="tts-1",
    voice="alloy",
    input="Hello from the Beaver SDK!"
)

with open("speech.mp3", "wb") as f:
    f.write(audio_bytes)

Advanced Configuration

Custom Base URL

beaver = Beaver(
    api_key="your-api-key",
    base_url="https://your-private-gateway.com/v1"
)

Parameters

The SDK now standardizes on max_tokens for all providers. max_output_tokens is supported as a legacy alias but is deprecated.

Error Handling

The SDK raises BeaverError for API failures.

from beaver_ai import Beaver, BeaverError

try:
    beaver.chat.completions.create(...)
except BeaverError as e:
    print(f"Error {e.status}: {e.message} (Code: {e.code})")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beaver_ai-0.2.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

beaver_ai-0.2.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file beaver_ai-0.2.1.tar.gz.

File metadata

  • Download URL: beaver_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for beaver_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4fcd16bba55323ab3914ec0738c5a0827b8275a2435638deab387b612bfeab27
MD5 75f19152f9a4be33621e8e0cd21d67a4
BLAKE2b-256 b6de175273b863f37c203b23db04450ed17c99f893755736d0463dd28b81751d

See more details on using hashes here.

File details

Details for the file beaver_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: beaver_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for beaver_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c14f6734ac8533a02614c7b13b7e01b13d50f43b69be3e50f8a2e3b6cf7bcf23
MD5 e829268e7ca9d47becf3df6685b27061
BLAKE2b-256 17054da22a9bf3501cbb7f774b600c69fa183796abeb45f54b3bbd96ed9861b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page