Skip to main content

Python SDK for Rheonic observability and protect preflight enforcement.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Rheonic Python SDK

Rheonic captures provider telemetry and applies protect preflight decisions before provider calls.

Install

pip install rheonic-sdk --pre

Required environment variables

RHEONIC_INGEST_KEY=<your_project_ingest_key>
RHEONIC_BASE_URL=<value_shown_in_dashboard>

Instrument provider calls

Wrap your provider SDK once.

Telemetry is captured automatically after each provider call.

Enforcement follows Project mode in the dashboard (Observe / Protect).

OpenAI:

import json
import os
from openai import OpenAI
from rheonic import create_client, instrument_openai, RHEONICBlockedError

rheonic = create_client(
    base_url=os.environ["RHEONIC_BASE_URL"],
    ingest_key=os.environ["RHEONIC_INGEST_KEY"],
)
openai_client = instrument_openai(
    OpenAI(api_key=os.environ["OPENAI_API_KEY"]),
    client=rheonic,
    endpoint="/chat/completions",
    feature="assistant",
)

try:
    openai_client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "hello"}],
        max_tokens=256,
    )
except RHEONICBlockedError as error:
    print(json.dumps({
        "reason": error.reason,
        "retry_after_seconds": error.retry_after_seconds,
        "blocked_until": error.blocked_until,
        "trace_id": error.trace_id,
        "request_id": error.request_id,
    }, indent=2))

Anthropic:

import json
import os
from anthropic import Anthropic
from rheonic import create_client, RHEONICBlockedError

rheonic = create_client(
    base_url=os.environ["RHEONIC_BASE_URL"],
    ingest_key=os.environ["RHEONIC_INGEST_KEY"],
)
anthropic_client = rheonic.instrument_anthropic(
    Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
)

try:
    anthropic_client.messages.create(
        model="claude-3-5-sonnet-latest",
        max_tokens=256,
        messages=[{"role": "user", "content": "hello"}],
    )
except RHEONICBlockedError as error:
    print(json.dumps({
        "reason": error.reason,
        "retry_after_seconds": error.retry_after_seconds,
        "blocked_until": error.blocked_until,
        "trace_id": error.trace_id,
        "request_id": error.request_id,
    }, indent=2))

Google:

import json
import os
import google.generativeai as genai
from rheonic import create_client, RHEONICBlockedError

rheonic = create_client(
    base_url=os.environ["RHEONIC_BASE_URL"],
    ingest_key=os.environ["RHEONIC_INGEST_KEY"],
)
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
google_model = rheonic.instrument_google(genai.GenerativeModel("gemini-1.5-pro"))

try:
    google_model.generate_content("hello")
except RHEONICBlockedError as error:
    print(json.dumps({
        "reason": error.reason,
        "retry_after_seconds": error.retry_after_seconds,
        "blocked_until": error.blocked_until,
        "trace_id": error.trace_id,
        "request_id": error.request_id,
    }, indent=2))

RHEONICBlockedError.reason is meant to be operator-relevant. The main values are:

  • tok_cap_breach
  • req_cap_breach
  • cooldown_active
  • fail_closed

If Protect is fail_open, timeout or availability problems stay internal and the provider call continues. If Protect is fail_closed, the SDK raises RHEONICBlockedError with the feedback fields shown above.

Keep one long-lived SDK client per app process. Initialize it during app startup and reuse it for all capture and instrumentation calls so Rheonic can avoid repeated protect cold-start latency.

Optional: custom event capture

Use this only if you can't instrument a provider SDK or need custom events.

import os
from rheonic import create_client, build_event

client = create_client(
    base_url=os.environ["RHEONIC_BASE_URL"],
    ingest_key=os.environ["RHEONIC_INGEST_KEY"],
)

client.capture_event(
    build_event(
        provider="openai",
        model="gpt-4o-mini",
        request={"endpoint": "/chat/completions", "feature": "assistant", "token_explosion_tokens": 64},
        response={"total_tokens": 64, "latency_ms": 120, "http_status": 200},
    )
)

token_explosion_tokens is optional. Set it only for custom/manual events when you want token-explosion detection to use the same request-context signal that the SDK instrumentation sends to both protect and ingest.

Reference

Full quickstart:

  • https://beta.rheonic.dev/quickstart

Support

support@rheonic.dev

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

rheonic_sdk-0.1.0b7.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

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

rheonic_sdk-0.1.0b7-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file rheonic_sdk-0.1.0b7.tar.gz.

File metadata

  • Download URL: rheonic_sdk-0.1.0b7.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for rheonic_sdk-0.1.0b7.tar.gz
Algorithm Hash digest
SHA256 931a596af64ff3026cb14f20bd409e0cc7576a9f408f628dbdb38b9f43a93d9b
MD5 7858c42450ba01016382b263420f1c2d
BLAKE2b-256 359ac7d5f38aa86b68514eefce9e4e9c05dbc8def34b388981b84311d45b4365

See more details on using hashes here.

File details

Details for the file rheonic_sdk-0.1.0b7-py3-none-any.whl.

File metadata

  • Download URL: rheonic_sdk-0.1.0b7-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for rheonic_sdk-0.1.0b7-py3-none-any.whl
Algorithm Hash digest
SHA256 660d3f1c43a5be531ca7f6422dc3c9c97cdb8808accf228ba5f590f215b16d4f
MD5 3ef4084ee262d0ed444a02f06225ce0f
BLAKE2b-256 de289798f27663174b5d5b1ae7c34863f77c6f004be83414e5a52609246155bc

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