Documentation OpenAI AI Wrapper
5 min read | June 24, 2026
Tutorial

OpenAI AI Wrapper

The Astralog OpenAI wrapper transparently monitors all your interactions with the OpenAI API. It captures token usage, prompts, completions, and latency.

View on GitHub

Installation

pip install astralog-openai astralog openai

Setup

# agent.py
from openai import OpenAI
from astralog import Client
from astralog.ai import track_openai

astralog_client = Client(api_key="ast_sk_live_xxxxxxxxxxxxx")
openai_client = OpenAI(api_key="sk-...")

# Seamlessly wrap the OpenAI client
tracked_openai = track_openai(openai_client, astralog_client)

# Use it normally. The wrapper will automatically extract:
# - Total tokens consumed
# - Model used
# - Call latency
# - Full prompts and responses
response = tracked_openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Cost Control & Visibility

By wrapping your LLM clients, Astralog generates specific ai_inference events in ClickHouse. You can use our Query Interface to instantly calculate your total token usage costs by model and detect prompt injections or hallucination anomalies.