Skip to main content

Python SDK for Till - activation-limited API key proxy

Project description

till

Python SDK for Till - activation-limited API key proxy.

Ship disposable API keys without handing over the real one. Give agents and contractors scoped access that auto-expires after N activations, tokens, or dollars spent.

Install

pip install till-ac

With OpenAI SDK support:

pip install till-ac[openai]

Quick start

Create and manage scoped keys

from till import TillClient

client = TillClient(admin_key="till_admin_...")

# Create a scoped key (50 activations, then dead)
key = client.create_key(
    provider="openai",
    upstream_key="sk-proj-...",
    max_activations=50,
    name="research-agent",
)

# This is shown once - save it
print(key.scoped_key)  # till_sk_abc123.xyz...

# List all keys
for k in client.list_keys():
    print(f"{k.metadata.get('name')}: {k.used_activations}/{k.max_activations}")

# Revoke a key
client.revoke_key(key.id)

Use scoped keys with OpenAI

The scoped key works as a drop-in replacement. Just point the base URL at Till:

import openai

client = openai.OpenAI(
    api_key="till_sk_abc123.xyz...",
    base_url="https://api.till.ac/v1",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)

Or use the helper:

from till.openai_compat import patched_openai

client = patched_openai("till_sk_abc123.xyz...")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)

Set token and dollar limits

# Key dies after 100K tokens OR $5, whichever comes first
key = client.create_key(
    provider="openai",
    upstream_key="sk-proj-...",
    max_activations=1000,
    max_tokens=100_000,
    max_spend_cents=500,  # $5.00
    name="budget-agent",
)

Async support

import asyncio
from till.client import AsyncTillClient

async def main():
    async with AsyncTillClient(admin_key="till_admin_...") as client:
        key = await client.create_key(
            provider="openai",
            upstream_key="sk-...",
            max_activations=50,
        )
        print(key.scoped_key)

asyncio.run(main())

Multi-provider

Till proxies to OpenAI, Anthropic, and Google. The scoped key holder doesn't need to know which provider they're hitting:

# OpenAI key
openai_key = client.create_key(
    provider="openai",
    upstream_key="sk-proj-...",
    max_activations=100,
)

# Anthropic key
anthropic_key = client.create_key(
    provider="anthropic",
    upstream_key="sk-ant-...",
    max_activations=100,
)

# Google key
google_key = client.create_key(
    provider="google",
    upstream_key="AIza...",
    max_activations=100,
)

Account info

account = client.account()
print(f"Plan: {account.tenant.plan}")
print(f"Keys: {account.keys_used}/{account.tenant.max_keys}")
print(f"Activations this month: {account.tenant.activations_this_month}")

Error handling

from till.client import TillError

try:
    key = client.create_key(...)
except TillError as e:
    print(f"Error {e.status_code}: [{e.code}] {e}")

How it works

  1. You create a scoped key via the admin API (this SDK)
  2. The upstream API key is encrypted into the scoped token - Till's database stores zero upstream keys
  3. Hand the scoped key to an agent/contractor
  4. They use it exactly like a normal API key (pointed at Till's proxy URL)
  5. After N activations (or token/dollar limit), the key auto-expires

Links

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

till_ac-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

till_ac-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file till_ac-0.1.1.tar.gz.

File metadata

  • Download URL: till_ac-0.1.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for till_ac-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2b411c8e1c9f96205cb304ba0cd5b47346db330cd2efe3486da96d21ab0fdaf5
MD5 47b91c5f0698b2f05a63408c334bb254
BLAKE2b-256 c1e4ab473292cddc86eee4f74404992eece1e4f744699efbace0c6d8039142ed

See more details on using hashes here.

File details

Details for the file till_ac-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: till_ac-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for till_ac-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 835958d7d3534c91c448d8da10833d4de6d5b6159605a32c860aa8873d4720d2
MD5 379776b01f38c6403f75439258d88340
BLAKE2b-256 27b85e821e738ce149829cef9753c4e8914b62056d7df987dfc3e5b4a881b68c

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