Sub topic 16
Provider differences and availability
This chapter assumes you can call an LLM API with a key, read JSON responses, and understand basic function calling. It also assumes you have seen the web search, code execution, and file search examples from earlier chapters. The goal here is to help you write code that survives a change of provider, model, or account, and to know where the differences are likely to bite.
Why the same idea looks different across providers
Every major provider hosts some tools itself. The model decides to call the tool, the provider runs it, and the results come back inside one response. The idea is shared, but the details are not. Request shapes, tool names, billing, output formats, and which models can use which tools all differ.
Two examples from this tutorial show the split:
- OpenAI's Responses API declares a tool with a short type, such as
{"type": "web_search"}. - Anthropic's Messages API declares a versioned server tool, such as
{"type": "web_search_20250305", "name": "web_search", "max_uses": 3}.
The versioned name matters. A date in the tool type is the provider's way of freezing behavior. When a newer version appears, the old one keeps working for a while, and new options usually ship only on the new version. Pin the version you tested, and read the provider's changelog when you upgrade.
Comparing the three tools
The table summarizes what to expect. It is a guide to the kinds of differences, not a price list or a guarantee. Provider catalogs change often, so confirm each row against current documentation before you build on it.
| Capability | OpenAI Responses API | Anthropic Messages API |
|---|---|---|
| Web search | `web_search` tool in `tools` | Versioned server tool such as `web_search_20250305`, with `max_uses` |
| Code execution | `code_interpreter` with a `container` setting | A separate code execution server tool, which may require a beta flag |
| File search | `file_search` with `vector_store_ids`, backed by provider vector stores | No equivalent hosted vector store in the same form. You usually retrieve documents yourself, or use a files feature |
| Citations | `url_citation` annotations on message text | Citation blocks attached to text blocks |
| Tool-call records | Items such as `web_search_call` in `response.output` | Server tool use and result blocks in `message.content` |
Other providers, such as Google with its Gemini API, offer their own grounding and code execution options. The pattern holds: the capability exists, but the request and response shapes are specific to each provider.
Differences that affect your code
Request shape
OpenAI's examples place the prompt in input and read response.output_text. Anthropic's examples place it in messages and require max_tokens. If you write a thin wrapper, keep the tool declaration inside the wrapper, so the rest of your app never sees a provider-specific dictionary.
Response shape
The final text is not found in the same place. With OpenAI, output_text is a convenience that joins the message text. With Anthropic, message.content is a list of blocks. It can hold text blocks, tool use blocks, and tool result blocks, and you must filter by block.type. Code that assumes one text block at index 0 breaks as soon as the model searches before it answers.
Citations
Both providers return sources, but the structure differs. OpenAI attaches url_citation annotations, with a title and URL, to parts of the answer text. Anthropic attaches citation data to text blocks. If your UI shows sources, write one function per provider that converts to a shared format.
Availability
A tool can be unavailable for several reasons:
- The model does not support it. Not every model in a family accepts every built-in tool.
- The feature is in beta or limited to certain accounts or regions.
- An organization admin has disabled it. Some providers let admins turn web search on or off for the whole organization.
- A platform that resells the model, such as a cloud marketplace, may expose a smaller set of tools than the provider's own API.
When a request fails with an error about an unknown or unsupported tool, check these four causes in that order.
A small adapter to isolate the differences
The following code defines one function that asks a question with web search enabled and returns plain text plus a list of sources, for either provider. It assumes the openai and anthropic packages are installed and that the matching API key environment variable is set.
from openai import OpenAI
import anthropic
def ask_with_search(provider, question):
"""Return (answer_text, sources) using the provider's web search tool."""
if provider == "openai":
client = OpenAI()
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "web_search"}],
input=question,
)
sources = []
for item in response.output:
if item.type == "message":
for part in item.content:
for ann in getattr(part, "annotations", []) or []:
if ann.type == "url_citation":
sources.append((ann.title, ann.url))
return response.output_text, sources
if provider == "anthropic":
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=[
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3,
}
],
messages=[{"role": "user", "content": question}],
)
text = ""
sources = []
for block in message.content:
if block.type == "text":
text += block.text
for cite in getattr(block, "citations", None) or []:
sources.append((getattr(cite, "title", ""), getattr(cite, "url", "")))
return text, sources
raise ValueError("unknown provider: " + provider)
answer, sources = ask_with_search("openai", "What are the most recent stable releases of Python?")
print(answer)
for title, url in sources:
print(title, url)The adapter hides three things: the tool declaration, the place where the text lives, and the place where citations live. Everything else in your app can work with (text, sources).
How the differences show up as failures
Common errors
- Hard-coding one provider's block layout. Reading
message.content[0].textworks until the model makes a tool call first. Loop and filter by type. - Assuming a feature exists everywhere. File search backed by a hosted vector store is an OpenAI feature in this tutorial's examples. If you move to Anthropic, you may need your own retrieval step and your own index.
- Copying a tool version from an old tutorial. A dated tool name may be retired. Check the current name before shipping.
- Ignoring data location. Hosted tools send your prompts, files, and search queries to the provider's infrastructure. If you have data residency or retention rules, check them for each provider and each tool, since policies can differ by tool.
- Comparing costs by token price alone. Search calls and container sessions may carry their own charges. Compare the whole bill for a typical request.
Decision criteria
Use a provider's built-in tool when it covers your need with little code and you accept the lock-in. Use a function tool, run by your own code, when you need to move between providers, control the data path, or need behavior the hosted tool does not offer. A reasonable middle path is an adapter like the one above, with a function-tool fallback behind the same interface.
Exercise
Your app works with OpenAI's web search and you are asked to add Anthropic as a second provider. Name three places where your code must change, and one failure you might see if you do not change them.
Show answer
The tool declaration changes ({"type": "web_search"} becomes a versioned server tool like web_search_20250305 with a name and optional max_uses). The request shape changes (input and output_text become messages, a required max_tokens, and a content list of blocks). The citation extraction changes (url_citation annotations on message parts become citation data on text blocks). A typical failure is reading message.content[0].text and getting a tool-use block or missing text, because the model made a search call before it answered.
Exercise
A request that includes a built-in tool returns an error saying the tool is not supported. List the causes to check, in a sensible order.
Show answer
First check whether the chosen model supports the tool. Then check that the tool type or version name is valid and current. Then check whether the tool is enabled for your account, region, or organization, since it may be in beta or disabled by an admin. If you call the model through a reseller or cloud platform, also check whether that platform exposes the tool at all.