OpenAI (GPT)

The OpenAI adapter connects opentine to GPT and o-series models via the OpenAI API. It supports tool calling across all models and chain-of-thought reasoning with o-series models.

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
)
  • 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.

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)               # "openai/gpt-4o"
6print(model.supports_tools)     # True
7print(model.supports_thinking)  # False
  • name — Returns "openai/{model}".
  • supports_tools — Always True. All OpenAI models support function calling.
  • supports_thinkingTrue if the model name starts with "o" (e.g. o3, o4-mini),False otherwise.

Supported Models

ModelToolsThinkingNotes
gpt-4oYesNoFlagship multimodal model
gpt-4o-miniYesNoFast and cost-effective
o3YesYesAdvanced reasoning
o4-miniYesYesFast reasoning, lower cost

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

Tool Calling

All OpenAI models support function calling. Pass your tools to the Agent and the model will invoke them as needed.

tool_use.py
1from opentine import Agent
2from opentine.models.openai import OpenAI
3from opentine.tools.web import search, fetch
4
5model = OpenAI("gpt-4o")
6
7agent = Agent(
8    model=model,
9    tools=[search, fetch],
10    system="Use the provided tools to answer questions with up-to-date information.",
11)
12
13run = 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) support chain-of-thought reasoning. When supports_thinking is True, opentine enables extended reasoning capabilities automatically.

reasoning.py
1from opentine.models.openai import OpenAI
2
3# o-series models enable reasoning / chain-of-thought
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
3from opentine.tools.python import execute
4
5# Use an o-series model for complex reasoning tasks
6model = OpenAI("o3")
7
8agent = Agent(
9    model=model,
10    tools=[execute],
11    system="You are a math tutor. Reason through problems step by step.",
12    max_steps=20,
13)
14
15run = agent.run_sync("Prove that the square root of 2 is irrational")

Next Steps