Skip to main content

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

License

MIT © Blackman AI

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

blackman_client-0.0.7.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blackman_client-0.0.7-py3-none-any.whl (62.2 kB view details)

Uploaded Python 3

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

Hashes for blackman_client-0.0.7.tar.gz
Algorithm Hash digest
SHA256 0ee1e31aa99916539bce3bd5f77a3afb3b9df9045e914a8c63edb46b0a5372e2
MD5 8b1f87b0842fc2fd7abb57ba83580f00
BLAKE2b-256 1cd9dec87d6b6d5b15c6ddb812a94fc4b77b982e2c3a93dc2c23ff02e7cf83b2

See more details on using hashes here.

File details

Details for the file blackman_client-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for blackman_client-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e6560c86a026c349a99a1c2f9b809462a8fa234be43a853d09326b061a7cb61f
MD5 979cb5201d48c9167691291a43b0936b
BLAKE2b-256 9c7463693349ba007b45acd6afb582024aa0465bbc4565ce4b9ad598813945ea

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