Blackman AI API
Project description
blackman-client
Official Python SDK for Blackman AI - The AI API proxy that optimizes token usage to reduce costs.
Features
- 🚀 Drop-in replacement for OpenAI, Anthropic, and other LLM APIs
- 💰 Automatic token optimization (save 20-40% on costs)
- 📊 Built-in analytics and cost tracking
- 🔒 Enterprise-grade security with SSO support
- ⚡ Low latency overhead (<50ms)
- 🎯 Semantic caching for repeated queries
Installation
pip install blackman-client
Or with Poetry:
poetry add blackman-client
Quick Start
import blackman_client
from blackman_client import CompletionRequest
configuration = blackman_client.Configuration(
host="https://app.useblackman.ai",
access_token="sk_your_blackman_api_key" # Get from https://app.useblackman.ai
)
with blackman_client.ApiClient(configuration) as api_client:
api = blackman_client.CompletionsApi(api_client)
response = api.completions(
CompletionRequest(
provider="OpenAI",
model="gpt-4o",
messages=[{"role": "user", "content": "Explain quantum computing in simple terms"}]
)
)
print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.total_tokens}")
print(f"Prompt tokens: {response.usage.prompt_tokens}")
Authentication
Get your API key from the Blackman AI Dashboard.
configuration = blackman_client.Configuration(
host="https://app.useblackman.ai",
access_token="sk_your_blackman_api_key"
)
Async Support
The SDK supports async operations:
import asyncio
import blackman_client
from blackman_client import CompletionRequest
async def main():
configuration = blackman_client.Configuration(
host="https://app.useblackman.ai",
access_token="sk_your_blackman_api_key"
)
async with blackman_client.ApiClient(configuration) as api_client:
api = blackman_client.CompletionsApi(api_client)
response = await api.completions_async(
CompletionRequest(
provider="OpenAI",
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
)
print(response.choices[0].message.content)
asyncio.run(main())
Framework Integration
Django
# settings.py
BLACKMAN_API_KEY = os.environ.get("BLACKMAN_API_KEY")
BLACKMAN_HOST = "https://app.useblackman.ai"
# views.py
import blackman_client
from django.conf import settings
def chat_view(request):
configuration = blackman_client.Configuration(
host=settings.BLACKMAN_HOST,
access_token=settings.BLACKMAN_API_KEY
)
with blackman_client.ApiClient(configuration) as api_client:
api = blackman_client.CompletionsApi(api_client)
# ... use api
FastAPI
from fastapi import FastAPI, Depends
import blackman_client
app = FastAPI()
def get_blackman_api():
configuration = blackman_client.Configuration(
host="https://app.useblackman.ai",
access_token=os.environ["BLACKMAN_API_KEY"]
)
with blackman_client.ApiClient(configuration) as api_client:
yield blackman_client.CompletionsApi(api_client)
@app.post("/chat")
async def chat(api: blackman_client.CompletionsApi = Depends(get_blackman_api)):
response = await api.completions_async(...)
return response
Advanced Usage
Custom Timeouts
configuration = blackman_client.Configuration(
host="https://app.useblackman.ai",
access_token="sk_your_api_key"
)
configuration.timeout = 60 # 60 seconds
with blackman_client.ApiClient(configuration) as api_client:
api = blackman_client.CompletionsApi(api_client)
# ... use api with custom timeout
Error Handling
from blackman_client.exceptions import ApiException
try:
response = api.completions(request)
except ApiException as e:
print(f"API error: {e.status} - {e.reason}")
print(f"Response body: {e.body}")
Documentation
Requirements
- Python 3.7+
- urllib3 >= 1.25.3
- python-dateutil
- pydantic >= 1.10.5, < 2
Support
- 📧 Email: support@blackman.ai
- 💬 Discord: Join our community
- 🐛 Issues: GitHub Issues
License
MIT © Blackman AI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
blackman_client-0.0.10.tar.gz
(38.1 kB
view details)
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 blackman_client-0.0.10.tar.gz.
File metadata
- Download URL: blackman_client-0.0.10.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0617d28580b938fe8d205594b2702b4b55a576502f9e87067f5e66dfe54b81de
|
|
| MD5 |
80373f09481c36addb0252befc5f005c
|
|
| BLAKE2b-256 |
b3a3f93f6dcef76cb610abee1ac1d25da52053cdf72ed8712c56f61d92dd33b1
|
File details
Details for the file blackman_client-0.0.10-py3-none-any.whl.
File metadata
- Download URL: blackman_client-0.0.10-py3-none-any.whl
- Upload date:
- Size: 74.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59e27ae572327aa8c47e46960055d95fd0bdc696af7b9da0f0a884b749e08164
|
|
| MD5 |
75187e52a241bd62f673c8c9343cf126
|
|
| BLAKE2b-256 |
ef9cf01bdb8424d9d1c8a145bdfc1d19f13538299806c8820bc86f331f973cde
|