Models¶
Direct API providers: OpenAI, Anthropic — plus any
OpenAI-compatible endpoint (vLLM, Ollama, together.ai, LiteLLM, …) via
OpenAIModel's base_url override. A
model is a string — the prefix before the colon selects the provider.
Registry¶
String factory — routes "openai:gpt-4o",
"anthropic:claude-sonnet-4-6", etc. to the right client.
get_model ¶
Get a model from a string identifier.
Format: "provider:model_name"
Examples:
- "openai:gpt-4o"
- "anthropic:claude-sonnet-4-6"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_string
|
str
|
Model identifier in "provider:model" format |
required |
**kwargs
|
Any
|
Provider-specific configuration |
{}
|
Returns:
| Type | Description |
|---|---|
ModelProtocol
|
Model instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If provider is unknown or model string is invalid |
Source code in .sdk/src/tulip/models/registry.py
list_providers ¶
register_provider ¶
Register a model provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Provider prefix (e.g., "openai", "anthropic") |
required |
factory
|
Callable[..., ModelProtocol]
|
Factory function that takes model name and kwargs |
required |
Source code in .sdk/src/tulip/models/registry.py
Base contract¶
Every model provider implements ModelProtocol. RequestBuilder and
ResponseParser are the per-provider seams for translating between
Tulip's ModelConfig / Message types and the provider's wire
format.
ModelProtocol ¶
Bases: Protocol
Protocol defining the model interface.
ModelConfig ¶
Bases: BaseModel
Base configuration for models.
ModelResponse ¶
Bases: BaseModel
Response from a model completion.
ResponseParser ¶
OpenAI¶
OpenAIModel ¶
OpenAIModel(model: str = 'gpt-4o', api_key: str | None = None, base_url: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, **kwargs: Any)
Bases: BaseModel
OpenAI model provider.
Supports GPT-4o, GPT-4, o1, o3, gpt-5.x models with streaming and tool
calling. Speaks both OpenAI wire APIs: chat-completions (the default)
and the Responses API, selected via api= on the config or
automatically for model families that require it (gpt-5.6-*, which
reject function tools on chat-completions whenever reasoning is on).
Example
model = OpenAIModel(model="gpt-4o") response = await model.complete([Message.user("Hello!")])
Initialize OpenAI model.
Source code in .sdk/src/tulip/models/native/openai.py
supports_structured_output
property
¶
Native response_format={"type":"json_schema",...} support.
OpenAI's chat-completions API accepts a JSON-schema response_format and guarantees a parseable instance. The agent loop uses this property to skip the prompted-JSON fallback when the provider ships native structured output.
client
property
¶
Get or create the OpenAI client.
The client is configured with explicit max_retries and
timeout from :class:OpenAIConfig so transient errors
(429, 5xx, network resets) don't kill the agent loop on first
try. The openai SDK retries with exponential backoff between
attempts.
Bound to the event loop that built it: AsyncOpenAI wraps an
httpx pool, so a client cached across two loops fails on the second
with APIConnectionError: Connection error — which reads as a
provider outage and sends you to check your key and their status page.
See :func:~tulip.core.loop_bound.loop_bound.
close
async
¶
__aenter__
async
¶
__aexit__
async
¶
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation history |
required |
tools
|
list[dict[str, Any]] | None
|
Tool schemas in OpenAI format |
None
|
**kwargs
|
Any
|
Additional OpenAI-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
ModelResponse
|
Model response with message and metadata |
Source code in .sdk/src/tulip/models/native/openai.py
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 | |
ainvoke
async
¶
LangChain-compatible alias — returns Message (AIMessage equivalent).
Source code in .sdk/src/tulip/models/native/openai.py
bind_tools ¶
LangChain-compatible bind_tools.
Source code in .sdk/src/tulip/models/native/openai.py
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
Conversation history |
required |
tools
|
list[dict[str, Any]] | None
|
Tool schemas in OpenAI format |
None
|
**kwargs
|
Any
|
Additional OpenAI-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[ModelChunkEvent]
|
Streaming chunks with content and/or tool calls |
Source code in .sdk/src/tulip/models/native/openai.py
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | |
OpenAIConfig ¶
Anthropic¶
AnthropicModel ¶
AnthropicModel(model: str = 'claude-sonnet-4-6', api_key: str | None = None, base_url: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, prompt_cache: bool = False, default_headers: dict[str, str] | None = None, **kwargs: Any)
Bases: BaseModel
Anthropic model provider.
Supports Claude 4.6, 4.5, 3.5 models with streaming and tool calling.
Example
model = AnthropicModel(model="claude-sonnet-4-6") response = await model.complete([Message.user("Hello!")])
Source code in .sdk/src/tulip/models/native/anthropic.py
supports_structured_output
property
¶
Anthropic doesn't ship OpenAI-style response_format.
The agent loop falls back to the prompted-JSON path with post-hoc parsing for Anthropic models.
client
property
¶
Get or create the Anthropic client.
Configured with explicit max_retries + timeout so a
transient 529 (overloaded) / 5xx / connection reset doesn't
kill the agent loop on the first try. Retries use exponential
backoff inside the anthropic SDK.
close
async
¶
Close the underlying httpx client.
Agent.run_sync calls this in a finally block so the
loop-bound httpx connections are shut down inside the same
event loop that opened them. Without this, the next
asyncio.run invocation closes the prior loop and the
leftover client's __del__ later tries to aclose against
it, raising RuntimeError: Event loop is closed.
Source code in .sdk/src/tulip/models/native/anthropic.py
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request.
Recognises an OpenAI-style response_format={"type": "json_schema", ...}
kwarg and translates it into Anthropic's tool-use mechanism: a synthetic
respond_with_schema tool is appended to the call and tool_choice
is pinned to it. The tool arguments are then surfaced as the message
content (canonical JSON) so callers can parse them with
:func:tulip.core.structured.parse_structured exactly as they would
with native response_format providers.
Source code in .sdk/src/tulip/models/native/anthropic.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.