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.2.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.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: beaver_ai-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9f7452aa067eea26c9bae728280134034fbb1d0db0ebcaa8d1ec294d47e973da
MD5 4d7310ec6acf4ca0476543d068873098
BLAKE2b-256 2cc720c4573bb7de91f427b314e159762fd83788ba5805c3e107bdb9effaaa8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: beaver_ai-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3db334dbb856569e8a6c396f8113c4f09596dd5e51c47d66beb568d7278a9bf5
MD5 5d19235ace7c6e1fe1e720eea7e39565
BLAKE2b-256 28991979e06015beefbb3110c6fa730498f826ce9f5d4713d60f0ca631fbcd1b

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