Skip to main content

Megflow AI API observability SDK — auto-instrument OpenAI, Anthropic, Gemini, AWS Bedrock and Cohere calls

Project description

megflow-observability

Python SDK for Megflow AI Observability — track tokens, cost, latency and errors across OpenAI, Anthropic, Gemini and more.

Install

pip install megflow-observability

Quick start

from megflow_observability import MegflowObserve

observe = MegflowObserve(api_key="obs_your_key_here")

observe.track(
    provider="openai",
    model="gpt-4o",
    input_tokens=100,
    output_tokens=50,
    total_tokens=150,
    cost_usd=0.00075,
    latency_ms=320,
    status_code=200,
)

Auto-instrument OpenAI

from openai import OpenAI
from megflow_observability import MegflowObserve, wrap_openai

client = wrap_openai(OpenAI(), MegflowObserve(api_key="obs_your_key_here"))

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

Auto-instrument Anthropic

import anthropic
from megflow_observability import MegflowObserve, wrap_anthropic

client = wrap_anthropic(anthropic.Anthropic(), MegflowObserve(api_key="obs_your_key_here"))

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

Auto-instrument Gemini

import google.generativeai as genai
from megflow_observability import MegflowObserve, wrap_gemini

genai.configure(api_key="YOUR_GOOGLE_API_KEY")
observe = MegflowObserve(api_key="obs_your_key_here")

model = wrap_gemini(genai.GenerativeModel("gemini-2.0-flash"), observe)
response = model.generate_content("Hello")

Auto-instrument AWS Bedrock

Works with Claude, Llama, Mistral, Titan and Cohere on Bedrock.

import boto3
import json
from megflow_observability import MegflowObserve, wrap_bedrock

observe = MegflowObserve(api_key="obs_your_key_here")
client = wrap_bedrock(
    boto3.client("bedrock-runtime", region_name="us-east-1"),
    observe,
)

response = client.invoke_model(
    modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
    body=json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "messages": [{"role": "user", "content": "Hello"}],
        "max_tokens": 1024,
    }),
)
result = json.loads(response["body"].read())

Auto-instrument Cohere

Works with both Client (v1) and ClientV2 (v2).

import cohere
from megflow_observability import MegflowObserve, wrap_cohere

observe = MegflowObserve(api_key="obs_your_key_here")

# v2 API
co = wrap_cohere(cohere.ClientV2("COHERE_API_KEY"), observe)
response = co.chat(
    model="command-r-plus",
    messages=[{"role": "user", "content": "Hello"}],
)

# v1 API
co = wrap_cohere(cohere.Client("COHERE_API_KEY"), observe)
response = co.chat(model="command-r-plus", message="Hello")

Prompt observability

Every wrap_*() function auto-computes a prompt_size (character count) and prompt_hash (SHA-256, first 16 chars) from the prompt-relevant input before sending anything — the raw prompt text itself is never transmitted. This lets the dashboard's Prompts page detect and group repeated prompts.

prompt_version has no natural source in an API call, so tag it explicitly per wrapped client:

client = wrap_openai(OpenAI(), observe, prompt_version="v3")

Optional dependencies

pip install megflow-observability[openai]      # includes openai
pip install megflow-observability[anthropic]   # includes anthropic
pip install megflow-observability[gemini]      # includes google-generativeai
pip install megflow-observability[all]         # includes all three

Links

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

megflow_observability-0.11.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

megflow_observability-0.11.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file megflow_observability-0.11.0.tar.gz.

File metadata

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

File hashes

Hashes for megflow_observability-0.11.0.tar.gz
Algorithm Hash digest
SHA256 03115afc5e5d57530aa798b0875943887ee7f1fa00c375599510c648654bb09d
MD5 046c88d29b37ea3576d632ce49dad33a
BLAKE2b-256 fb613c6becb089b827bd0dc4bf7e86bf1faa6e77b211b41e8bf093e8132d38b4

See more details on using hashes here.

File details

Details for the file megflow_observability-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for megflow_observability-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d96130b9ac15adc47f77ced56632aae0a817d1abb7267f2284dc8e0cdcdfb323
MD5 fc516386dd566ddc6dd01799558ff951
BLAKE2b-256 bb1634beb0a6a4f4d4ba74eab0065a4942f35f6b1ab82633480f7ee0ec81c5a7

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