Back to Guides

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

FieldDescription
ModelThe AI model identifier
TemperatureSampling temperature
Max TokensMaximum response tokens
MessagesConversation message array
Prompt HashSHA-256 hash of prompt
Response TimeAPI call duration
Token UsageInput/output token counts
CostEstimated API cost

Verify

Open your Decyra dashboard and navigate to the traces section. Each API call will be visible with full context and metrics.

Next Steps