OpenAI (GPT)

The OpenAI adapter connects opentine to GPT and o-series models via the OpenAI API. It exposes OpenAI function-calling schemas and reports a supports_thinking capability flag for model names starting witho. Cloud live validation requires your OpenAI credentials.

Installation

Install opentine with the OpenAI extra to pull in the required SDK.

Terminal
pip install "opentine[openai]"

Quick Start

agent.py
1from opentine import Agent
2from opentine.models.openai import OpenAI
3
4# Uses OPENAI_API_KEY env var by default
5model = OpenAI("gpt-4o")
6
7agent = Agent(model=model, tools=[...])
8run = agent.run_sync("Analyze the pros and cons of microservices vs monoliths")

Constructor

Signature
OpenAI(
    model: str = "gpt-4o",
    api_key: str | None = None,  # Falls back to OPENAI_API_KEY env var
    base_url: str | None = None, # Falls back to OPENAI_BASE_URL env var
)
  • model — The OpenAI model identifier. Defaults to "gpt-4o".
  • api_key — Your OpenAI API key. If not provided, the adapter falls back to the OPENAI_API_KEY environment variable.
  • base_url — Optional OpenAI-compatible endpoint. If not provided, the adapter falls back to OPENAI_BASE_URL.

Authentication

You can provide your API key either directly in the constructor or via an environment variable.

auth.py
1from opentine.models.openai import OpenAI
2
3# Explicit API key (overrides env var)
4model = OpenAI("gpt-4o", api_key="sk-...")
5
6# Or set the environment variable
7# export OPENAI_API_KEY="sk-..."

Properties

properties.py
1from opentine.models.openai import OpenAI
2
3model = OpenAI("gpt-4o")
4
5print(model.name)               # "gpt-4o"
6print(model.supports_tools)     # True
7print(model.supports_thinking)  # False
  • name — Returns the model identifier passed to the constructor.
  • supports_toolsTrue in the adapter. Provider and model-specific tool behavior should be validated in your live gate.
  • supports_thinkingTrue if the model name starts with "o" (e.g. o3, o4-mini),False otherwise.

Supported Models

ModelTool SchemaThinking FlagNotes
gpt-4oExposedNoFlagship multimodal model
gpt-4o-miniExposedNoFast and cost-effective
o3ExposedExposedAdvanced reasoning
o4-miniYesYesFast reasoning, lower cost

Any valid OpenAI model identifier can be passed to the constructor.

Tool Calling

The adapter converts opentine tool schemas to OpenAI function definitions. Pass your tools to the Agent and validate the selected model in your environment.

tool_use.py
1from opentine import Agent
2from opentine.models.openai import OpenAI
3from opentine.tools.search import search
4from opentine.tools.web import fetch
5
6model = OpenAI("gpt-4o")
7
8agent = Agent(
9    model=model,
10    tools=[search, fetch],
11    system="Use the provided tools to answer questions with up-to-date information.",
12)
13
14run = agent.run_sync("What were the top tech acquisitions this year?")

O-Series Reasoning

Models whose names start with "o" (such as o3 and o4-mini) are reported with supports_thinking=True. This is a capability flag today; opentine does not automatically add provider-specific reasoning controls.

reasoning.py
1from opentine.models.openai import OpenAI
2
3# supports_thinking is a capability flag for o-series model names.
4o3 = OpenAI("o3")
5print(o3.supports_thinking)     # True — model name starts with "o"
6
7o4_mini = OpenAI("o4-mini")
8print(o4_mini.supports_thinking) # True
9
10gpt4o = OpenAI("gpt-4o")
11print(gpt4o.supports_thinking)  # False — "gpt" does not start with "o"

O-series models are particularly effective for math, logic, and multi-step planning tasks.

reasoning_agent.py
1from opentine import Agent
2from opentine.models.openai import OpenAI
3
4# Use an o-series model for complex reasoning tasks.
5model = OpenAI("o3")
6
7agent = Agent(
8    model=model,
9    system="You are a math tutor. Reason through problems step by step.",
10    max_steps=20,
11)
12
13run = agent.run_sync("Prove that the square root of 2 is irrational")

Next Steps