Anthropic (Claude)

The Anthropic adapter connects opentine to Claude models via the Anthropic API. It supports tool use, extended thinking, and all Claude model variants including Opus, Sonnet, and Haiku.

Installation

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

Terminal
pip install "opentine[anthropic]"

Quick Start

agent.py
1from opentine import Agent
2from opentine.models.anthropic import Anthropic
3
4# Uses ANTHROPIC_API_KEY env var by default
5model = Anthropic("claude-sonnet-4-20250514")
6
7agent = Agent(model=model, tools=[...])
8run = agent.run_sync("Summarize the latest AI research papers")

Constructor

Signature
Anthropic(
    model: str = "claude-sonnet-4-20250514",
    api_key: str | None = None,  # Falls back to ANTHROPIC_API_KEY env var
)
  • model — The Claude model identifier. Defaults to "claude-sonnet-4-20250514".
  • api_key — Your Anthropic API key. If not provided, the adapter falls back to the ANTHROPIC_API_KEY environment variable.

Authentication

You can provide your API key either directly in the constructor or via an environment variable. The environment variable approach is recommended for production use.

auth.py
1from opentine.models.anthropic import Anthropic
2
3# Explicit API key (overrides env var)
4model = Anthropic("claude-sonnet-4-20250514", api_key="sk-ant-...")
5
6# Or set the environment variable
7# export ANTHROPIC_API_KEY="sk-ant-..."

Properties

properties.py
1from opentine.models.anthropic import Anthropic
2
3model = Anthropic("claude-sonnet-4-20250514")
4
5print(model.name)               # "anthropic/claude-sonnet-4-20250514"
6print(model.supports_tools)     # True
7print(model.supports_thinking)  # True
  • name — Returns "anthropic/{model}".
  • supports_tools — Always True. All Claude models support native tool use.
  • supports_thinkingTrue if the model name contains "opus" or "sonnet", False otherwise.

Supported Models

ModelToolsThinkingNotes
claude-opus-4-20250514YesYesMost capable, best for complex tasks
claude-sonnet-4-20250514YesYesBest balance of speed and capability
claude-haiku-3-20240307YesNoFastest and most cost-effective

Any valid Claude model identifier can be passed to the constructor. The table above lists the most commonly used models.

Tool Use

Claude models have native tool use support. Pass your tools to the Agent and Claude will decide when and how to call them.

tool_use.py
1from opentine import Agent
2from opentine.models.anthropic import Anthropic
3from opentine.tools.web import search, fetch
4
5model = Anthropic("claude-sonnet-4-20250514")
6
7# Claude models have native tool use support
8agent = Agent(
9    model=model,
10    tools=[search, fetch],
11    system="Search the web to answer questions accurately.",
12)
13
14run = agent.run_sync("What is the current population of Tokyo?")

Extended Thinking

Opus and Sonnet models support extended thinking, which allows the model to reason through complex problems step-by-step before responding. Whensupports_thinking is True, opentine automatically enables this capability.

thinking.py
1from opentine.models.anthropic import Anthropic
2
3# Extended thinking is automatically enabled for Opus and Sonnet models
4opus = Anthropic("claude-opus-4-20250514")
5print(opus.supports_thinking)   # True
6
7sonnet = Anthropic("claude-sonnet-4-20250514")
8print(sonnet.supports_thinking) # True
9
10haiku = Anthropic("claude-haiku-3-20240307")
11print(haiku.supports_thinking)  # False

Next Steps

  • Model Adapters — Overview of all available adapters
  • OpenAI (GPT) — Use GPT-4o or o-series reasoning models
  • Tools — Built-in tools for web, filesystem, and more