#!/usr/bin/env python3
"""
OpenAI Client Wrapper Example

Demonstrates how to use the Agent Status OpenAI wrapper for automatic
metrics tracking on all OpenAI API calls.

Requirements:
    pip install agent-status-sdk[openai]
"""

import os
from agent_status.integrations.openai_wrapper import AgentStatusOpenAI

RORA_API_KEY = os.environ.get("RORA_API_KEY", "your_rora_key")

client = AgentStatusOpenAI(rora_api_key=RORA_API_KEY)

print("Making OpenAI API calls...")

for i in range(3):
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "user", "content": f"Say hello in language #{i+1}"}
        ],
        max_tokens=50,
    )
    print(f"Response {i+1}: {response.choices[0].message.content}")

print("\nAgent Status Metrics:")
metrics = client.rora_metrics
print(f"  Total Requests: {metrics['total_requests']}")
print(f"  Successful: {metrics['successful_requests']}")
print(f"  Failed: {metrics['failed_requests']}")
print(f"  Avg Latency: {metrics['avg_latency_ms']:.0f} ms")
print(f"  Total Tokens: {metrics['total_tokens']}")
print(f"  Success Rate: {metrics['success_rate']:.1%}")

print("\nPer-Model Breakdown:")
for model, stats in metrics['by_model'].items():
    print(f"  {model}: {stats['requests']} requests, {stats['latency_ms']:.0f} ms total")
