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

Uploaded Python 3

File details

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

File metadata

  • Download URL: beaver_ai-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 788193c82d72319c172836039696d2a3c39f9e2121e2a59a72c08a952277f354
MD5 d77e304400a1277d1577b01f8b250f96
BLAKE2b-256 fa1b0e9df4d37c8d15d5b6e4cd53632150629e16cd6d9f9ba0b45341b7eddbb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: beaver_ai-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d995e29fa7fb39d42d82bcae881bdbfc887a6eae3229e37438aeb1352f94ef
MD5 a2467f626b36e6b4d739a5dc2961ef13
BLAKE2b-256 ed1ff2d9761083a33d29a19bb4bcf313b8c4d766341cfc60a73934b356a81423

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