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.
pip install "opentine[openai]"Quick Start
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
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 theOPENAI_API_KEYenvironment variable.base_url— Optional OpenAI-compatible endpoint. If not provided, the adapter falls back toOPENAI_BASE_URL.
Authentication
You can provide your API key either directly in the constructor or via an environment variable.
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
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_tools—Truein the adapter. Provider and model-specific tool behavior should be validated in your live gate.supports_thinking—Trueif the model name starts with"o"(e.g.o3,o4-mini),Falseotherwise.
Supported Models
| Model | Tool Schema | Thinking Flag | Notes |
|---|---|---|---|
gpt-4o | Exposed | No | Flagship multimodal model |
gpt-4o-mini | Exposed | No | Fast and cost-effective |
o3 | Exposed | Exposed | Advanced reasoning |
o4-mini | Yes | Yes | Fast 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.
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.
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.
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
- Model Adapters — Overview of all available adapters
- Anthropic (Claude) — Use Claude with extended thinking
- OpenAI-Compatible Providers — Use provider wrappers or a custom base URL