Skip to main content

OKAP Logo

OKAP Python SDK

Python SDK for OKAP (Open Key Access Protocol) - Secure API key delegation.

Installation

pip install okap

For vault server functionality:

pip install okap[vault]

Quick Start

For Apps (Requesting Access)

from okap import OkapClient

# Connect to user's vault
client = OkapClient(
    vault_url="https://vault.example.com",
    app_name="My AI App"
)

# Request access to OpenAI
token = client.request_access(
    provider="openai",
    models=["gpt-4", "gpt-4o-mini"],
    capabilities=["chat"],
    monthly_limit=10.00,  # $10/month max
    reason="For AI-powered features"
)

# Use with OpenAI SDK - just change base_url
from openai import OpenAI

ai = OpenAI(
    api_key=token.token,
    base_url=token.base_url  # Points to vault proxy
)

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

For Vaults (Hosting Keys)

from okap.vault import OkapVault, MemoryStorage
from fastapi import FastAPI

app = FastAPI()
vault = OkapVault(
    storage=MemoryStorage(),
    base_url="https://vault.example.com"
)

# Add your API keys
vault.add_key("openai", "sk-...")
vault.add_key("anthropic", "sk-ant-...")

@app.post("/okap/request")
def handle_request(request: dict):
    from okap.models import AccessRequest
    req = AccessRequest.model_validate(request)
    
    # In production, show approval UI to user first!
    # For demo, auto-approve:
    return vault.approve_request(req)

Features

  • Secure delegation: Master keys never leave the vault
  • Usage limits: Set spend caps and rate limits per app
  • Expiration: Tokens auto-expire
  • Revocable: Revoke access instantly
  • Provider agnostic: Works with OpenAI, Anthropic, Google, etc.

Models

AccessRequest

from okap import AccessRequest

request = AccessRequest(
    provider="openai",
    models=["gpt-4"],
    capabilities=["chat", "embeddings"],
    limits=Limits(monthly_spend=10.00),
    expires="2025-03-01",
    reason="For my cool app"
)

OkapToken

from okap import OkapToken

# Returned after approval
token = OkapToken(
    token="okap_abc123...",
    base_url="https://vault.example.com/v1/openai",
    provider="openai",
    models=["gpt-4"],
    expires_at=datetime(2025, 3, 1)
)

Error Handling

from okap import OkapClient
from okap.errors import AccessDeniedError, VaultError

try:
    token = client.request_access(provider="openai")
except AccessDeniedError as e:
    print(f"User denied access: {e}")
except VaultError as e:
    print(f"Vault error: {e}")

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check .

License

MIT

Metadata

Release files for okap 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for okap 0.1.2
File Size Uploaded
okap-0.1.2.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for okap 0.1.2
File Interpreter ABI Platform
okap-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / okap-0.1.2.tar.gz

Download URL okap-0.1.2.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
19409e3bdaa5966a1c3ba8d3a934bcabe6ead60735ba46cfbe48b3526a51c462
BLAKE2b-256 checksum
How to use checksums
86c3a6a082c345da3fd20563b1633530b744673eb09530a44ada1983ba81edd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / okap-0.1.2-py3-none-any.whl

Download URL okap-0.1.2-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f801e7fcd9f0805da12a3efc8efd2f5396699b2a72ea8d139db244f19b005f2f
BLAKE2b-256 checksum
How to use checksums
37b8d4cd565c9cb1e9ef934b90c96b54ca929e783f19eb1c091c170faa7e9729
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page