Skip to content

agentix.providers.openai

openai

OpenAI model adapter (Chat Completions API).

Translates between agentix's framework-agnostic types and OpenAI's chat API via the official openai package — install with pip install "agentix[openai]". The import is deferred to construction so import agentix works without it.

Because the wire format is the OpenAI Chat Completions shape, this adapter also drives any OpenAI-compatible endpoint: pass base_url= (and an api_key your gateway accepts) to point it at vLLM, Together, Groq, a local server, etc. For Ollama specifically see :class:~agentix.providers.ollama.OllamaModel.

OpenAIModel

OpenAIModel(
    *,
    model: str = DEFAULT_MODEL,
    api_key: str | None = None,
    base_url: str | None = None,
    client: Any = None,
    **extra: Any,
)

A :class:~agentix.model.ModelFn backed by OpenAI Chat Completions.

Example::

from agentix import Agent
from agentix.providers.openai import OpenAIModel

agent = Agent(model=OpenAIModel(model="gpt-4o"), system_prompt="...")

extra keyword arguments are forwarded to chat.completions.create — e.g. temperature, response_format for JSON mode, or reasoning_effort for reasoning models. Tool schemas carrying strict are forwarded for OpenAI strict structured tool calls. Pricing for unknown model ids is 0.0 until registered via :func:agentix.register_price.

with_response_format

with_response_format(schema: dict[str, Any]) -> OpenAIModel

Return a copy that enforces JSON-schema output (used by Agent(response_model=…)).