Models¶
Native providers: OpenAI (openai:), Anthropic (anthropic:),
Azure OpenAI (azure:) and Amazon Bedrock (bedrock:). Also
routed by name: a table of OpenAI-compatible prefixes, such as ollama:,
vllm:, lmstudio:, groq:, together:, openrouter:, deepseek:,
mistral: and gemini:. Each prefix has its own default endpoint and
API-key variable. Any other OpenAI-compatible endpoint works through
openai-compatible:<model> with an explicit base_url=. See
OpenAI-compatible providers.
A model is a string — the prefix before the colon selects the provider.
For the concepts, start with Model providers.
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
CompatibleProvider
dataclass
¶
CompatibleProvider(prefix: str, base_url: str | None, env_key: str, label: str, env_base_url: str | None = None, requires_key: bool = True)
One OpenAI-compatible endpoint, addressable by prefix.
Attributes:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
The |
base_url |
str | None
|
Default endpoint. |
env_key |
str
|
Environment variable holding the API key. |
label |
str
|
Human-readable name, used in the provider table and errors. |
env_base_url |
str | None
|
Provider-conventional environment variable that
overrides |
requires_key |
bool
|
When |
tulip_base_url_env
property
¶
The TULIP_-namespaced base-URL override for this provider.
resolve_base_url ¶
Resolve the endpoint: explicit > TULIP_ override > vendor env > default.
Source code in .sdk/src/tulip/models/providers/__init__.py
resolve_api_key ¶
Resolve the API key: explicit > provider env > placeholder-or-None.
Source code in .sdk/src/tulip/models/providers/__init__.py
register_compatible_providers ¶
Register every entry in :data:COMPATIBLE_PROVIDERS.
Called from the registry's default registration. Safe to call twice — registration is a dict assignment keyed by prefix.
Source code in .sdk/src/tulip/models/providers/__init__.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
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
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.
With stream_reconnects (0 by default) each turn is read whole before any of it
is yielded, and a turn whose connection drops part way is asked again, up to that
many times. Partial output is never yielded, so the caller never sees half a turn
twice. Inside an NVIDIA OpenShell box a connection is cut whenever the box's policy
generation moves on (its first settings poll after start does so), and the OpenAI
client retries a request that failed but never a stream that broke after it began.
A refusal (an HTTP status, e.g. a guard's token_budget_exhausted) is not retried.
Source code in .sdk/src/tulip/models/native/openai.py
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, auth_token: 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.
base_url
property
¶
The endpoint requests go to: the configured one, else ANTHROPIC_BASE_URL.
wire_model
property
¶
The model id as the endpoint names it.
OpenRouter's Messages API takes its own slugs, so a Claude id is translated there; an id already written as a slug is sent unchanged.
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
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a chat response.
Sends the same request :meth:complete does — temperature, prompt
caching, native-tool betas and response_format included — and
reports the same usage, cache counters included.
Source code in .sdk/src/tulip/models/native/anthropic.py
AnthropicConfig ¶
Azure OpenAI¶
See Azure OpenAI.
AzureOpenAIModel ¶
AzureOpenAIModel(model: str, endpoint: str | None = None, api_version: str | None = None, api_key: str | None = None, **kwargs: Any)
Bases: OpenAIModel
Azure OpenAI provider.
Example
model = AzureOpenAIModel(model="gpt4o-prod") # a deployment name response = await model.complete([Message.user("Hello!")])
Source code in .sdk/src/tulip/models/native/azure.py
client
property
¶
An AsyncAzureOpenAI, which is an AsyncOpenAI subclass.
Loop-bound for the same reason as the OpenAI client: it wraps an httpx
pool, and one cached across two event loops fails on the second with
APIConnectionError — which reads as a provider outage rather than
the caching bug it is.
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.
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
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
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.
With stream_reconnects (0 by default) each turn is read whole before any of it
is yielded, and a turn whose connection drops part way is asked again, up to that
many times. Partial output is never yielded, so the caller never sees half a turn
twice. Inside an NVIDIA OpenShell box a connection is cut whenever the box's policy
generation moves on (its first settings poll after start does so), and the OpenAI
client retries a request that failed but never a stream that broke after it began.
A refusal (an HTTP status, e.g. a guard's token_budget_exhausted) is not retried.
Source code in .sdk/src/tulip/models/native/openai.py
AzureOpenAIConfig ¶
Amazon Bedrock¶
Needs the bedrock extra (pip install "tulip-agents[bedrock]"). See
Amazon Bedrock.
BedrockModel ¶
BedrockModel(model: str = 'us.amazon.nova-lite-v1:0', region: str | None = None, profile: str | None = None, max_tokens: int = 4096, temperature: float = 0.7, **kwargs: Any)
Bases: BaseModel
Amazon Bedrock provider, via the Converse API.
Example
model = BedrockModel(model="us.amazon.nova-micro-v1:0") response = await model.complete([Message.user("Hello!")])
Source code in .sdk/src/tulip/models/native/bedrock.py
supports_structured_output
property
¶
Converse has no response_format.
It could be emulated by forcing a single tool via toolChoice, the
way the Anthropic provider does — but toolChoice support varies by
model on Bedrock, and a structured-output path that works on Claude and
silently fails on Llama is worse than not claiming it. The agent loop
falls back to prompted JSON, which every Bedrock model handles.
client
property
¶
The bedrock-runtime client, built once and reused.
Deliberately not wrapped in :func:tulip.core.loop_bound. That helper
exists for clients whose connection pool binds to the event loop that
created it — httpx, redis.asyncio, asyncpg. A botocore client is
synchronous and holds no loop reference, so it survives being used from
whatever thread :func:asyncio.to_thread happens to hand it to, and
rebuilding it per loop would only pay the (slow) client construction
cost again.
complete
async
¶
complete(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> ModelResponse
Complete a chat request through converse.
botocore is synchronous, so the call runs on a worker thread. Without that, every Bedrock request would block the event loop for its whole duration — which for an agent means no concurrent tool execution, no streaming consumer, and no timeout firing.
Source code in .sdk/src/tulip/models/native/bedrock.py
stream
async
¶
stream(messages: list[Message], tools: list[dict[str, Any]] | None = None, **kwargs: Any) -> AsyncIterator[ModelChunkEvent]
Stream a response through converse_stream.
botocore's event stream is a synchronous iterator, so it is drained on
a worker thread into a bounded thread-safe queue and read back with
:func:asyncio.to_thread. An asyncio.Queue would be the wrong tool:
its put_nowait is not safe to call from another thread, and the
resulting corruption shows up as dropped or duplicated chunks under
load rather than as an error.
Source code in .sdk/src/tulip/models/native/bedrock.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
close
async
¶
Release the underlying client.