Skip to main content

BYO - Python SDK for BYOK

Project description

BYO PYTHON SDK for BYOK

Official Python SDK for BYO — BYOK (Bring Your Own Key).

Installation

pip install byok

Quick Start

import os
from byo import BYOK

byok = BYOK(api_key=os.environ["BYOK_API_KEY"])

# Proxy an OpenAI request
openai = byok.openai(ref_id="customer_123")
response = openai.responses.create(
    model="gpt-4.1",
    input="Hello from BYOK!"
)
print(response)

OpenAI

Responses API

openai = byok.openai(ref_id="customer_123")
response = openai.responses.create(model="gpt-4.1", input="What is BYOK?")

Chat Completions API

openai = byok.openai(ref_id="customer_123")
response = openai.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Hello!"}]
)

Anthropic

Messages API

claude = byok.anthropic(ref_id="customer_123")
response = claude.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

Google AI Studio

Generate Content

gemini = byok.google(ref_id="customer_123")
response = gemini.generate_content.create(
    model="gemini-2.0-flash",
    contents=[{"parts": [{"text": "Hello!"}]}]
)

Azure OpenAI

Chat Completions

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

Azure OpenAI requires provider_config when connecting the key:

byok.keys.connect(
    provider="azure-openai",
    ref_id="customer_123",
    provider_key="your-azure-api-key",
    provider_config={
        "baseUrl": "https://your-resource.openai.azure.com",
        "deploymentName": "gpt-4",
    },
)

AWS Bedrock

Converse

bedrock = byok.bedrock(ref_id="customer_123")
response = bedrock.converse.create(
    modelId="anthropic.claude-3-haiku-20240307-v1:0",
    messages=[{"role": "user", "content": [{"text": "Hello!"}]}]
)

AWS Bedrock requires provider_config when connecting the key:

byok.keys.connect(
    provider="bedrock",
    ref_id="customer_123",
    provider_key="your-aws-secret-access-key",
    provider_config={
        "accessKeyId": "AKIA...",
        "region": "us-east-1",
    },
)

Key Management

# Connect a provider key
byok.keys.connect(
    provider="openai",
    ref_id="customer_123",
    provider_key="sk-..."
)

# Validate a stored key
result = byok.keys.validate(provider="openai", ref_id="customer_123")

# Revoke a stored key
byok.keys.revoke(provider="openai", ref_id="customer_123")

Error Handling

from byo import BYOK, BYOKError, AuthenticationError

try:
    response = openai.responses.create(model="gpt-4.1", input="Hello")
except AuthenticationError:
    print("Invalid API key")
except BYOKError as e:
    print(f"Error {e.status_code}: {e.message}")

License

FSL-1.1-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

byok-0.2.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

byok-0.2.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file byok-0.2.2.tar.gz.

File metadata

  • Download URL: byok-0.2.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for byok-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cd8e5610a87503913a0227dacf1a41b95edb7f888a35385162e3b0af907540c7
MD5 ff8f6a7c6bbfadb497a980d886dc09a5
BLAKE2b-256 2ccbad36d3742d313357b1a5bdb7a1468a33a1a051a4e285eff8dbdfa348ebe8

See more details on using hashes here.

Provenance

The following attestation bundles were made for byok-0.2.2.tar.gz:

Publisher: release.yml on treadiehq/byo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file byok-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: byok-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for byok-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b421514fd171aa7e72f3b0e55a2fc0c55c12420df9029db7672f7fe4ada8c984
MD5 78cf1873af3e4dce7958b70455c3e23a
BLAKE2b-256 6467ace268ab511e7a09bd7c608443a49cd125bc608eff02f23201db9296026b

See more details on using hashes here.

Provenance

The following attestation bundles were made for byok-0.2.2-py3-none-any.whl:

Publisher: release.yml on treadiehq/byo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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