Skip to main content

Behest AI Python SDK — dual-mode (API key or local sign), auth.mint, chat completions with streaming, threads, usage, typed errors. Install: `pip install behest-ai`; import: `from behest import Behest`.

Project description

Behest Python SDK

The official Python SDK for Behest AI -- extends the OpenAI Python SDK with Behest authentication and local JWT signing.

Installation

pip install behest

Quick Start

API Key Flow

from behest import BehestClient

client = BehestClient(api_key="bh_live_YOUR_API_KEY")

response = client.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[{"role": "user", "content": "Hello, Behest!"}],
)
print(response.choices[0].message.content)

Local Signing Flow (Tenant Signing Keys)

For server-to-server use cases where you want to eliminate the mint round-trip (~1ms local signing vs 50-200ms mint):

import os
from behest import BehestSigningClient

client = BehestSigningClient(
    signing_key_pem=os.environ["BEHEST_SIGNING_KEY_PEM"],
    key_id=os.environ["BEHEST_SIGNING_KEY_ID"],   # "sk_a1b2c3..."
    tenant_id=os.environ["BEHEST_TENANT_ID"],
    project_id=os.environ["BEHEST_PROJECT_ID"],
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello from Python!"}],
)
print(response.choices[0].message.content)

Manual Token Signing

from behest.signing import sign_behest_jwt

result = sign_behest_jwt(
    private_key_pem=os.environ["BEHEST_SIGNING_KEY_PEM"],
    key_id="sk_a1b2c3...",
    tenant_id="your-tenant-id",
    project_id="your-project-id",
    user_id="alice",
    expires_in=3600,
)
print(result["access_token"])

Streaming

stream = client.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[{"role": "user", "content": "Write a poem about the sea."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Error Handling

from behest import BehestClient
from behest.errors import (
    AuthenticationError,
    RateLimitError,
    BehestError,
)

client = BehestClient(api_key="bh_live_YOUR_API_KEY")

try:
    response = client.chat.completions.create(
        model="gemini-2.5-flash",
        messages=[{"role": "user", "content": "Hello"}],
    )
except AuthenticationError:
    print("Check your API key.")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after_ms}ms")
except BehestError as e:
    print(f"Behest error {e.status}: {e}")

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

behest_ai-1.5.0b1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

behest_ai-1.5.0b1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file behest_ai-1.5.0b1.tar.gz.

File metadata

  • Download URL: behest_ai-1.5.0b1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for behest_ai-1.5.0b1.tar.gz
Algorithm Hash digest
SHA256 d7f104c482c838d3b93817c607913265b29269b75e7d586e8aa63add2966d233
MD5 219af61c7c67698054044979425f8712
BLAKE2b-256 5bab08550a159f5be9b05148dbb3bff97499bc2b3d022ec83642cbf2ceb6fcf2

See more details on using hashes here.

File details

Details for the file behest_ai-1.5.0b1-py3-none-any.whl.

File metadata

  • Download URL: behest_ai-1.5.0b1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for behest_ai-1.5.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 a064e17c5f674f26ed507400a256126a9d163960dab2999fab2e2e59c5ee7bbd
MD5 f462e85dc79a87120e6c8e8e34486bf7
BLAKE2b-256 47d1700c288e27bb3562cc473fcf5a4adf6c88e284adc89119070848412869c1

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