In short.
Pydantic AI’s Dependencies guide is a tutorial for Python developers connecting services to AI agents, but its HTTP examples need application-specific services and configuration. It explains how deps_type, per-run deps and RunContext connect instructions, tools and output validators to shared objects. It also demonstrates dependency overrides, although these alone do not demonstrate offline or model-free testing. No code was executed; compatibility, operating costs and runtime behavior were not assessed.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage is the complete selected page at [https://pydantic.dev/docs/ai/core-concepts/dependencies/index.md], including its introductory documentation-index and query-parameter notices and all embedded examples. The documentation index, linked API pages, installation material elsewhere, and linked Weather Agent, SQL Generation and RAG examples are excluded. No code or tests were executed; runtime behavior, example outputs, model availability and production suitability remain unverified.
The overview
What this guide covers
This is the Dependencies page in the Pydantic AI documentation at [https://pydantic.dev/docs/ai/core-concepts/dependencies/index.md]. It explains dependency injection: supplying objects such as an HTTP client and API key to agent functions instead of constructing them inside each function.
The resource is a feature guide with annotated Python examples. It is not a standalone application, installable extension or complete introduction to Pydantic AI.
Fit for your work
The guide is useful when an agent needs application services in several places, such as an instruction builder, a tool and an output validator. It follows the same dependency container through those functions and then shows how application tests can replace its behavior.
Its main gap is surrounding setup: installation, provider credentials and working implementations of the example HTTP services are not supplied. The documentation’s claims about testability and production use are not supported here by execution results or deployment measurements.
Who it helps
Python developers already building Pydantic AI agents are the clearest audience. Beginners can follow the progression from a dependency container to functions that use it, but will need familiarity with classes, dataclasses, decorators, type annotations and async functions.
Experienced developers can use the sections on static typing, thread-pool execution and scoped overrides to assess integration with existing application code. The guide does not teach those Python concepts from scratch.
What the page demonstrates
Dependencies can be any Python type. The examples group an API key and HTTP client in a dataclass, then access them from instructions, a tool and an output validator. The validator demonstrates raising ModelRetry when its external validation request returns status 400.
The page also describes dependency fields in template strings, access to agent and realtime-session information through RunContext, and replacement dependencies within an agent.override context. These are documented capabilities; their runtime behavior was not assessed.
Using it
What you need
Using the examples requires Python, Pydantic AI and httpx for the HTTP clients shown. A static type checker is needed to obtain the described type-checking feedback. The page supplies no installation command, supported Python range or package versions.
The examples configure an agent with an OpenAI model identifier, but do not explain model credentials or establish model availability. Credentials and service implementations for a real application are also outside the supplied setup.
How dependency passing works
Pass the dependency type to the Agent constructor through deps_type, then pass an actual object through deps when running the agent. Functions receive a RunContext parameter annotated with that dependency type and access the object through ctx.deps. The page explicitly describes deps_type as a static typing aid that is not used at runtime.
Agent functions run in an asynchronous context. Synchronous instructions, tools and validators are dispatched through run_in_executor in a thread pool. Choosing run_sync instead of run does not change this execution model; the page recommends async functions when dependencies perform I/O.
How to apply the pattern
Define a container such as MyDeps, configure Agent with deps_type=MyDeps, construct the container with your client and other values, and supply it to agent.run through deps. Annotate functions that need the container with RunContext[MyDeps]. The asynchronous examples manage the HTTP client with an async context manager.
For most asynchronous snippets, the page explicitly requires importing asyncio and adding asyncio.run(main()). These additions provide the entry point; they do not supply installation, model authentication or the external service implementations.
The complete example
The full example uses one dependency object containing an API key and asynchronous HTTP client. An instructions function fetches text, a joke-material tool makes an authenticated request with a subject parameter, and an output validator submits generated text to an external service. A status-400 validation response triggers ModelRetry; other HTTP errors are raised.
The later application example moves instruction creation into a dependency method. A test subclass returns fixed instructions, and agent.override supplies that subclass while the application calls the agent. The displayed joke outputs and assertion are documentation examples, not observed execution results.
Assessment & evidence
Limits to keep in mind
The page does not provide implementations for the HTTP services used in its examples. It also supplies no measurements of latency, concurrency behavior or reliability. Successful execution and production suitability remain unverified.
Because deps_type is documented as a static typing aid, it should not be treated as proof that runtime objects, credentials or services are valid. Likewise, replacing dependencies in the shown test does not demonstrate complete isolation from the configured model.
Why this pattern may fit
The examples suggest a practical benefit for agents that share authenticated services: instructions, tools and validators can obtain those services through the same typed container. This makes the required objects visible in function annotations and agent configuration.
The override example also shows a way to substitute dependency behavior without changing application code that calls the agent. These are benefits illustrated by the design, rather than measured improvements in development speed, correctness or deployment readiness.
Choices described on the page
For a simple dependency, the page permits passing a single object; for several objects, it recommends a dataclass container. It demonstrates both asynchronous and synchronous HTTP clients, with async functions preferred for I/O.
For tests, replacement dependencies can be supplied directly when calling the agent, or through agent.override when application code owns that call. The page does not compare competing agent libraries or dependency-injection frameworks.
What supports these findings
The available evidence is the complete Dependencies documentation page, including explanatory text, annotated Python snippets and an application-test example. It supports describing the documented API pattern and intended behavior.
No code was executed. Printed outputs, the test assertion and statements about production use do not establish successful operation. Linked API references and linked application examples are outside the available evidence.
Access & freshness
Costs
The page gives no prices, usage allowances or model-request costs. Charges for the configured model and any external HTTP services are unknown, as are total execution and testing costs.
The override example changes dependencies without showing a replacement for the configured model. Consequently, it does not establish that running the example test avoids model calls or provider charges.
Reuse terms
The supplied page contains no license notice or redistribution terms for its prose or code examples. Their reuse terms, and the underlying library’s license, are unknown from this evidence.
Version and date limits
The supplied page was captured on 23 November 2026 at 13:38:06 UTC. It states no publication date, last-updated date or Pydantic AI release number.
Compatibility with a particular installed release, availability of the named model and changes after the capture are unknown. The capture date does not establish when the documented behavior was introduced.
Practical next steps
Start with one dependency container and an instructions function, then add tools or validators where your application needs them. Adapt the external services, establish model configuration and check compatibility with your installed Pydantic AI version.
Use a static checker to assess the annotations and verify dependency replacement through your own application entry point. If you require offline tests, plan model substitution separately: the shown override replaces dependencies only. Establish provider and service costs before running model-backed examples.
