Skip to main content

AI Cost Intelligence SDK — track, attribute, and reduce AI inference costs

Project description

runesignal Python SDK

Track, attribute, and reduce AI inference costs — per customer, per feature, per endpoint.

Install

pip install runesignal

Quick start

import runesignal

# Call once at startup
runesignal.configure(api_key="rs_live_YOUR_KEY")

# Decorate any async function that calls an LLM
@runesignal.track(customer_id=user.id, feature_tag="summarize", endpoint_id="POST /summarize")
async def summarize(text: str) -> str:
    response = await openai_client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": text}],
    )
    return response.choices[0].message.content

That's it. RuneSignal captures model, token counts, cost, and latency — then ships the log in the background without blocking your code.

What gets captured

Field Source
model response.model
input_tokens response.usage.prompt_tokens
output_tokens response.usage.completion_tokens
cached_tokens response.usage.prompt_tokens_details.cached_tokens
cost_usd Calculated from current pricing table
latency_ms Wall-clock time around your function
customer_id Your parameter
feature_tag Your parameter
endpoint_id Your parameter (defaults to function name)

Supported providers

Works with any provider that returns an OpenAI-compatible response object (.usage.prompt_tokens, .usage.completion_tokens). Explicitly tested with:

  • OpenAI (openai ≥ 1.0)
  • Anthropic (anthropic ≥ 0.25, returns .usage.input_tokens / .usage.output_tokens)
  • Google Gemini (via google-generativeai with OpenAI-compat adapter)

Proxy mode (no decorator needed)

Instead of decorating individual functions, you can route all OpenAI calls through the RuneSignal proxy. The proxy forwards requests unchanged and logs in the background:

import openai
import runesignal

runesignal.configure(api_key="rs_live_YOUR_KEY")

client = openai.AsyncOpenAI(
    base_url=runesignal.proxy_url(),   # https://api.runesignal.com/proxy/openai/v1
    api_key="your-openai-key",         # still required by the OpenAI SDK
    default_headers={"X-Customer-Id": user.id},
)

Safety guarantees

  • Never raises — all exceptions inside the SDK are swallowed. Your code path is never affected.
  • Never blocks — logs are shipped with asyncio.create_task (fire-and-forget).
  • Never stores prompts or completions — only token counts and metadata.

Environment variables

Variable Description
RUNESIGNAL_API_KEY Your RuneSignal API key (alternative to configure(api_key=...))
RUNESIGNAL_BASE_URL Override the ingest endpoint (useful for self-hosted or local dev)

Pricing table

The SDK ships with a built-in pricing table (runesignal._cost_table.PRICING). It covers all major OpenAI, Anthropic, and Gemini models. Update it by bumping the SDK version or overriding PRICING directly.

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

runesignal-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.

runesignal-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: runesignal-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for runesignal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 467179d2bf4239653d704df9fe16b2978b0b84f0a6bfada4828accd4c3eb159d
MD5 51ab97484ddf77d7e537c04ceab0c679
BLAKE2b-256 9322c18c86f5bb8e3b9318777b1e2bc2f7f25ef6030bc046e6b7bf0815bc56c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for runesignal-0.1.0.tar.gz:

Publisher: publish-sdk.yml on richardsplit/RuneSignal

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

File details

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

File metadata

  • Download URL: runesignal-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for runesignal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79e5c5bc743d72d3170ab8a32f00ff670cbc373bea624ebd0b8e30c487c5ee52
MD5 174c3e4f38219ad73d9684b9ecb1ed4c
BLAKE2b-256 9f5159716860784fa2fe3227494f77918f2a0a7c85843dd5b95ad408c9585c23

See more details on using hashes here.

Provenance

The following attestation bundles were made for runesignal-0.1.0-py3-none-any.whl:

Publisher: publish-sdk.yml on richardsplit/RuneSignal

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