OpenAI Python
Official OpenAI SDK for Python applications
Pythoneasy
The OpenAI Python SDK is the official Python client for OpenAI's API. Route requests through Decyra's proxy to capture all API interactions and gain comprehensive observability.
Prerequisites
- Decyra account with API key
- Python 3.8+ installed
- OpenAI package installed
Installation
pip install openai decyra-sdk
Integration
Configure OpenAI client with Decyra's proxy:
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DECYRA_API_KEY"),
base_url="https://proxy.decyra.com/v1",
default_headers={
"X-Decyra-API-Key": os.getenv("DECYRA_API_KEY")
}
)
Use the client for chat completions:
completion = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": "Explain machine learning"}
],
temperature=0.7,
)
print(completion.choices[0].message.content)
What Gets Captured
| Field | Description |
|---|---|
| Model | The AI model identifier |
| Temperature | Sampling temperature |
| Max Tokens | Maximum response tokens |
| Messages | Conversation message array |
| Prompt Hash | SHA-256 hash of prompt |
| Response Time | API call duration |
| Token Usage | Input/output token counts |
| Cost | Estimated API cost |
Verify
Open your Decyra dashboard and navigate to the traces section. Each API call will be visible with full context and metrics.