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.7.tar.gz
(34.5 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.7.tar.gz.
File metadata
- Download URL: blackman_client-0.0.7.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ee1e31aa99916539bce3bd5f77a3afb3b9df9045e914a8c63edb46b0a5372e2
|
|
| MD5 |
8b1f87b0842fc2fd7abb57ba83580f00
|
|
| BLAKE2b-256 |
1cd9dec87d6b6d5b15c6ddb812a94fc4b77b982e2c3a93dc2c23ff02e7cf83b2
|
File details
Details for the file blackman_client-0.0.7-py3-none-any.whl.
File metadata
- Download URL: blackman_client-0.0.7-py3-none-any.whl
- Upload date:
- Size: 62.2 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 |
e6560c86a026c349a99a1c2f9b809462a8fa234be43a853d09326b061a7cb61f
|
|
| MD5 |
979cb5201d48c9167691291a43b0936b
|
|
| BLAKE2b-256 |
9c7463693349ba007b45acd6afb582024aa0465bbc4565ce4b9ad598813945ea
|