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 identifiermessages(list[dict], required): List of message dictionaries withroleandcontenttemperature(float, optional): Sampling temperature (0-2)max_output_tokens(int, optional): Maximum tokens to generatetop_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 codecode(str | None): Beaver error codemessage(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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7db8adab0a940ddd0d52627f7ba966bf4ef1ab3e5a6189e594629717da25d7e1
|
|
| MD5 |
8173ec77e77899eaaed136f660af20e9
|
|
| BLAKE2b-256 |
0e4720bd6f8bd31c303de69130eb4bd738d692eff28df875c623b8563b606ecb
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c43dc12a56ca0ce5cbe29b33ec9d115947635991a15acdac05545d09fa67976
|
|
| MD5 |
296599515a9882b55e8589a8c08433ba
|
|
| BLAKE2b-256 |
5d87c3037265b859f28040a899b4c85f29fb1bad6bceed5254ca202f59553921
|