Skip to main content

Lightweight cost-attribution wrapper for Anthropic, OpenAI, and Google Gemini Python SDKs

Project description

affixly-surge-sdk

Lightweight cost-attribution wrapper for the Anthropic, OpenAI, and Google Gemini Python SDKs. Track AI spend by product line, feature, and customer with a one-line import change — no proxy, no infrastructure, no code rewrite.

PyPI distribution name: affixly-surge-sdk. Python import name: surge_sdk. They differ because surge-sdk was already taken on PyPI by an unrelated project — the import name we control stays clean.

Install

pip install affixly-surge-sdk

Install alongside whichever provider SDK you use:

pip install "affixly-surge-sdk[anthropic]"   # Anthropic (Claude)
pip install "affixly-surge-sdk[openai]"      # OpenAI (GPT)
pip install "affixly-surge-sdk[gemini]"      # Google Gemini
pip install "affixly-surge-sdk[all]"         # All three

Quick start

from surge_sdk import anthropic, configure

configure(
    surge_api_url="https://your-surge-backend-url",
    surge_api_key="surge_sk_your_key_here",
    product_line="my-app",
)

client = anthropic.Anthropic(api_key="sk-ant-...")
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
# Tracked automatically. No further code changes needed.

Get your surge_api_key from your Surge dashboard at Settings → SDK → Generate API key.

Per-call tags

Attribute spend to a specific feature or customer:

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[...],
    surge_tags={"feature": "summarize", "customer_id": "cust_abc123"},
)

How it works

  • The wrapper intercepts messages.create() (or the equivalent for OpenAI / Gemini), reads token counts from the response, and POSTs a usage event to your Surge backend on a background thread.
  • Your AI calls go directly to the provider — no proxy, no added latency.
  • If Surge is unreachable, the report is dropped silently. Your application is never affected.

Supported providers

Provider Import What's tracked
Anthropic from surge_sdk import anthropic messages.create(), messages.stream()
OpenAI from surge_sdk import openai chat.completions.create()
Google Gemini from surge_sdk import gemini as genai models.generate_content()

Both sync and async clients are supported for all providers.

Documentation

Full guide: see docs/getting-started.md.

License

MIT — see LICENSE.

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

affixly_surge_sdk-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

affixly_surge_sdk-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file affixly_surge_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: affixly_surge_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for affixly_surge_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 db6977466225e966cef231865d83394db7653350f2b33d483effbbdbbfec995c
MD5 2e60997c13efe02ded6dd0f49089d18c
BLAKE2b-256 2b55ba7d8b20362c8a1376b52122f140380ffc98d8ebf1e7ad10b01f12497c64

See more details on using hashes here.

File details

Details for the file affixly_surge_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for affixly_surge_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47ffc902fb24fa5b9adfdc5ca33240768e9390f926c276bb7dd350ea9135cb0e
MD5 c57897fe466fd67d0fb7ab3d2416d8c3
BLAKE2b-256 41416fdf7fb4dabdd86597355d993a1ce20f7c46ac61552987226f92acb705ed

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