Skip to main content

AnoSys SDK for OpenAI - Automatic instrumentation and logging for OpenAI API calls

Project description

AnoSys SDK for OpenAI

License: Apache 2.0 Python

Automatically capture and send OpenAI API calls to AnoSys for monitoring, analytics, and observability.

Features

Automatic OpenAI Instrumentation - Captures all OpenAI API calls via OpenTelemetry
Streaming Support - Detects and logs streaming responses
OpenTelemetry Semantic Conventions - Follows Gen AI standards
Error Tracking - Captures exceptions with full stack traces
Zero Configuration - Works out of the box with just your API key

Installation

pip install anosys-sdk-openai

Quick Start

import os
from openai import OpenAI
from anosys_sdk_openai import AnosysOpenAILogger

os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["ANOSYS_API_KEY"] = "your-anosys-key"

# Initialize (do once at startup)
AnosysOpenAILogger()

# Use OpenAI normally - all calls are automatically logged
client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)
print(response.choices[0].message.content)

Streaming

Streaming is automatically detected and logged:

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Write a haiku"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Custom Function Logging

You can also log custom functions using decorators from the core package:

from anosys_sdk_core import anosys_logger

@anosys_logger(source="my_app")
def process_response(response):
    return response.choices[0].message.content

What Data is Captured?

Following OpenTelemetry Gen AI standards:

  • gen_ai.system - Always "openai"
  • gen_ai.request.model - Model requested
  • gen_ai.response.model - Model that responded
  • gen_ai.request.temperature - Temperature parameter
  • gen_ai.usage.input_tokens - Input token count
  • gen_ai.usage.output_tokens - Output token count
  • Request/response messages
  • Timestamps and duration
  • Error details

Environment Variables

Variable Required Description
ANOSYS_API_KEY Yes Your AnoSys API key
OPENAI_API_KEY Yes Your OpenAI API key

License

Apache 2.0

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

anosys_sdk_openai-1.0.13.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

anosys_sdk_openai-1.0.13-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file anosys_sdk_openai-1.0.13.tar.gz.

File metadata

  • Download URL: anosys_sdk_openai-1.0.13.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anosys_sdk_openai-1.0.13.tar.gz
Algorithm Hash digest
SHA256 c9c8d48f2563d5290cd20481fc604e54c17e1b94b16f4cb527f762f306183c1c
MD5 7a3ed0a95a7c072e6f77f6eed0fe7fa2
BLAKE2b-256 5a61d477eeeccdfe2c861a86c81ce16f229c3faff79481ddd3df1d1df9906191

See more details on using hashes here.

File details

Details for the file anosys_sdk_openai-1.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for anosys_sdk_openai-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 1a52408209395f2fe2348bb697beeaaa4149a04f42c1ec5e74c523ed0733a72e
MD5 eb0b8a05870c7aba4e81dd3b810dae4b
BLAKE2b-256 65e7e70fa41ec688c2c564b1ae5b3e3979a7e797750ea6d0b53e67c4390ab4f4

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