Skip to main content

Python SDK for the Beaver AI Gateway

Project description

Beaver AI Python SDK

Python SDK for the Beaver AI Gateway.

Installation

pip install beaver-ai

Quick Start

from beaver_ai import Beaver

beaver = Beaver(api_key="your-api-key")

response = beaver.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[
        {"role": "user", "content": "Hello, how are you?"}
    ]
)

print(response["choices"][0]["message"]["content"])

Configuration

Constructor Options

beaver = Beaver(
    api_key="your-api-key",      # Required
    base_url="http://localhost:8080"  # Optional, defaults to http://localhost:8080
)

API Reference

Chat Completions

Create a chat completion request.

response = beaver.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"}
    ],
    temperature=0.7,           # Optional
    max_output_tokens=1000,    # Optional
    top_p=1.0                  # Optional
)

Request Parameters

  • model (str, required): Model identifier
  • messages (list[dict], required): List of message dictionaries with role and content
  • temperature (float, optional): Sampling temperature (0-2)
  • max_output_tokens (int, optional): Maximum tokens to generate
  • top_p (float, optional): Nucleus sampling parameter

Response Format

{
    "id": str,
    "model": str,
    "choices": [
        {
            "index": int,
            "message": {
                "role": "assistant",
                "content": str
            },
            "finish_reason": str | None
        }
    ],
    "usage": {  # Optional
        "prompt_tokens": int,
        "completion_tokens": int,
        "total_tokens": int
    }
}

Error Handling

The SDK raises BeaverError for non-2xx responses.

from beaver_ai import Beaver, BeaverError

beaver = Beaver(api_key="your-api-key")

try:
    response = beaver.chat.completions.create(
        model="gemini-2.5-flash",
        messages=[{"role": "user", "content": "Hello"}]
    )
except BeaverError as e:
    print(f"Error {e.status}: {e.message}")
    print(f"Code: {e.code}")

Error Properties

  • status (int): HTTP status code
  • code (str | None): Beaver error code
  • message (str): Error message

Custom Base URL

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

Model Support

The SDK accepts model identifiers as strings. Currently supported and documented model: gemini-2.5-flash.

Type Hints

The SDK includes type hints for better IDE support.

from beaver_ai import ChatCompletionRequest, ChatCompletionResponse

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.1.0.tar.gz (3.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.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: beaver_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 3.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.1.0.tar.gz
Algorithm Hash digest
SHA256 7db8adab0a940ddd0d52627f7ba966bf4ef1ab3e5a6189e594629717da25d7e1
MD5 8173ec77e77899eaaed136f660af20e9
BLAKE2b-256 0e4720bd6f8bd31c303de69130eb4bd738d692eff28df875c623b8563b606ecb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: beaver_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c43dc12a56ca0ce5cbe29b33ec9d115947635991a15acdac05545d09fa67976
MD5 296599515a9882b55e8589a8c08433ba
BLAKE2b-256 5d87c3037265b859f28040a899b4c85f29fb1bad6bceed5254ca202f59553921

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