Skip to main content

Orbit SDK for Python

Track, monitor, and optimize your AI spend across OpenAI, Anthropic, and other LLM providers.

Installation

pip install orbithq-sdk

# With OpenAI support
pip install orbithq-sdk[openai]

# With Anthropic support
pip install orbithq-sdk[anthropic]

# With all providers
pip install orbithq-sdk[all]

Quick Start

1. Get your API key

Sign up at Orbit and create an API key.

2. Initialize the SDK

from orbithq_sdk import Orbit

orbit = Orbit(
    api_key="orb_live_xxxxxxxxxxxxxxxxxxxxxxxx",
    default_feature="my-app",  # Optional: default feature for all events
)

3. Track your LLM calls

Option A: Automatic tracking (Recommended)

Wrap your OpenAI or Anthropic client for automatic tracking:

from openai import OpenAI
from orbithq_sdk import Orbit, WrapperOptions

orbit = Orbit(api_key="orb_live_xxx")
openai = orbit.wrap_openai(OpenAI(), WrapperOptions(feature="chat-assistant"))

# All API calls are now automatically tracked!
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello, world!"}],
)

Works with Anthropic too:

from anthropic import Anthropic
from orbithq_sdk import Orbit, WrapperOptions

orbit = Orbit(api_key="orb_live_xxx")
anthropic = orbit.wrap_anthropic(Anthropic(), WrapperOptions(feature="document-analysis"))

message = anthropic.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Analyze this document..."}],
)

Option B: Manual tracking

For other providers or custom implementations:

from orbithq_sdk import Orbit

orbit = Orbit(api_key="orb_live_xxx")

# Track a successful request
orbit.track(
    model="gpt-4o",
    input_tokens=150,
    output_tokens=50,
    latency_ms=1234,
    feature="summarization",
    environment="production",
)

# Track an error
orbit.track_error(
    model="gpt-4o",
    error_type="rate_limit_exceeded",
    error_message="Rate limit exceeded",
    feature="chat-assistant",
    input_tokens=150,
)

Configuration

from orbithq_sdk import Orbit, OrbitConfig

orbit = Orbit(config=OrbitConfig(
    # Required
    api_key="orb_live_xxx",

    # Optional
    base_url="https://orbit-analytics.vercel.app/api/v1",  # Custom API endpoint
    default_feature="my-app",                    # Default feature name
    default_environment="production",            # 'production' | 'staging' | 'development'
    debug=False,                                 # Enable debug logging

    # Batching (for high-volume applications)
    batch_events=True,       # Batch events before sending
    batch_size=10,           # Max events per batch
    batch_interval=5.0,      # Max seconds before sending batch

    # Reliability
    retry=True,              # Retry failed requests
    max_retries=3,           # Max retry attempts
))

Feature Attribution

Features are Orbit's key differentiator - they let you see exactly which parts of your application are consuming AI resources:

# Track different features
orbit.track(
    model="gpt-4o",
    input_tokens=100,
    output_tokens=50,
    feature="chat-assistant",  # Attribute to chat feature
)

orbit.track(
    model="gpt-4o",
    input_tokens=500,
    output_tokens=200,
    feature="document-analysis",  # Attribute to doc analysis
)

Then in the Orbit dashboard, you'll see:

  • Cost breakdown by feature
  • Request volume by feature
  • Error rates by feature
  • And more!

Context Manager Support

from orbithq_sdk import Orbit

with Orbit(api_key="orb_live_xxx") as orbit:
    orbit.track(model="gpt-4o", input_tokens=100, output_tokens=50)
# Automatically flushes on exit

Graceful Shutdown

For long-running processes, flush events before exit:

# Before your process exits
orbit.shutdown()

Event Properties

Property Type Required Description
model str Yes Model name (e.g., 'gpt-4o', 'claude-3-opus')
input_tokens int Yes Number of input tokens
output_tokens int Yes Number of output tokens
provider str No Provider name (auto-detected if not provided)
latency_ms int No Request latency in milliseconds
feature str No Feature name for attribution
environment str No Environment ('production', 'staging', 'development')
status str No Request status ('success', 'error', 'timeout')
error_type str No Error type if status is 'error'
error_message str No Error message if status is 'error'
user_id str No Your application's user ID
session_id str No Session ID for grouping requests
request_id str No Unique request ID for tracing
metadata dict No Additional key-value metadata

License

MIT

Metadata

Release files for orbithq-sdk 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 orbithq-sdk 0.1.2
File Size Uploaded
orbithq_sdk-0.1.2.tar.gz 11.5 kB Details

Built distribution (wheel)

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

Total release size: 24.2 kB

Release files / orbithq_sdk-0.1.2.tar.gz

Download URL orbithq_sdk-0.1.2.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c12f8d22ca5d00cbf900c8bda024ee8a71b9ec9a3deb606ee2384b0d30b8a8e3
BLAKE2b-256 checksum
How to use checksums
31daef6dc95057dc4b84c5a440d69c30d74d3d9def5c08a3e643e0bd859e13c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

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

Download URL orbithq_sdk-0.1.2-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
695f4bbd1bd041598fcdfb82990753e4509d4f246ee7e6e766bd6dd21d8e040b
BLAKE2b-256 checksum
How to use checksums
8f93604965dc17efdfb1ebc39fc3785dedfedb42c493048d9705162e77650a8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

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