Skip to content

Openai

pip install datapizza-ai-clients-openai

datapizza.clients.openai.OpenAIClient

Bases: Client

A client for interacting with the OpenAI API.

This class provides methods for invoking the OpenAI API to generate responses based on given input data. It extends the Client class.

__init__

__init__(
    api_key,
    model="gpt-4o-mini",
    system_prompt="",
    temperature=None,
    cache=None,
    base_url=None,
    organization=None,
    project=None,
    webhook_secret=None,
    websocket_base_url=None,
    timeout=None,
    max_retries=2,
    default_headers=None,
    default_query=None,
    http_client=None,
)

Parameters:

Name Type Description Default
api_key str

The API key for the OpenAI API.

required
model str

The model to use for the OpenAI API.

'gpt-4o-mini'
system_prompt str

The system prompt to use for the OpenAI API.

''
temperature float | None

The temperature to use for the OpenAI API.

None
cache Cache | None

The cache to use for the OpenAI API.

None
base_url str | URL | None

The base URL for the OpenAI API.

None
organization str | None

The organization ID for the OpenAI API.

None
project str | None

The project ID for the OpenAI API.

None
webhook_secret str | None

The webhook secret for the OpenAI API.

None
websocket_base_url str | URL | None

The websocket base URL for the OpenAI API.

None
timeout float | Timeout | None

The timeout for the OpenAI API.

None
max_retries int

The max retries for the OpenAI API.

2
default_headers dict[str, str] | None

The default headers for the OpenAI API.

None
default_query dict[str, object] | None

The default query for the OpenAI API.

None
http_client Client | None

The http_client for the OpenAI API.

None

Usage example

from datapizza.clients.openai import OpenAIClient

client = OpenAIClient(
    api_key="YOUR_API_KEY",
    model="gpt-4o-mini",
)
response = client.invoke("Hello!")
print(response.text)

Include thinking

from datapizza.clients.openai import OpenAIClient

client = OpenAIClient(
    model= "gpt-5",
    api_key="YOUR_API_KEY",
)

response = client.invoke("Hi",reasoning={
        "effort": "low",
        "summary": "auto"
    }
)
print(response)