Skip to content

Commit cd64b45

Browse files
authored
Merge branch 'main' into anthropic-prompt-caching-only
2 parents 5e29917 + a28ec53 commit cd64b45

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

docs/dependencies.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pydantic AI uses a dependency injection system to provide data and services to your agent's [system prompts](agents.md#system-prompts), [tools](tools.md) and [output validators](output.md#output-validator-functions).
44

5-
Matching Pydantic AI's design philosophy, our dependency system tries to use existing best practice in Python development rather than inventing esoteric "magic", this should make dependencies type-safe, understandable easier to test and ultimately easier to deploy in production.
5+
Matching Pydantic AI's design philosophy, our dependency system tries to use existing best practice in Python development rather than inventing esoteric "magic", this should make dependencies type-safe, understandable, easier to test, and ultimately easier to deploy in production.
66

77
## Defining Dependencies
88

@@ -103,11 +103,11 @@ _(This example is complete, it can be run "as is" — you'll need to add `asynci
103103
[System prompt functions](agents.md#system-prompts), [function tools](tools.md) and [output validators](output.md#output-validator-functions) are all run in the async context of an agent run.
104104

105105
If these functions are not coroutines (e.g. `async def`) they are called with
106-
[`run_in_executor`][asyncio.loop.run_in_executor] in a thread pool, it's therefore marginally preferable
106+
[`run_in_executor`][asyncio.loop.run_in_executor] in a thread pool. It's therefore marginally preferable
107107
to use `async` methods where dependencies perform IO, although synchronous dependencies should work fine too.
108108

109109
!!! note "`run` vs. `run_sync` and Asynchronous vs. Synchronous dependencies"
110-
Whether you use synchronous or asynchronous dependencies, is completely independent of whether you use `run` or `run_sync``run_sync` is just a wrapper around `run` and agents are always run in an async context.
110+
Whether you use synchronous or asynchronous dependencies is completely independent of whether you use `run` or `run_sync``run_sync` is just a wrapper around `run` and agents are always run in an async context.
111111

112112
Here's the same example as above, but with a synchronous dependency:
113113

docs/gateway.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,31 @@ Choose a name for your organization (or accept the default). You will automatica
5454
A default project will be created for you. You can choose to use it, or create a new one on the [Projects](https://gateway.pydantic.dev/admin/projects) page.
5555

5656
### Add **Providers**
57+
5758
There are two ways to use Providers in the Pydantic AI Gateway: you can bring your own key (BYOK) or buy inference through the platform.
5859

5960
#### Bringing your own API key (BYOK)
6061

61-
On the [Providers](https://gateway.pydantic.dev/admin/providers) page, fill in the form to add a provider. Paste your API key into the form under Credentials, and make sure to **select the Project that will be associated to this provider**. It is possible to add multiple keys from the same provider.
62+
On the [Providers](https://gateway.pydantic.dev/admin/providers) page, fill in the form to add a provider.
63+
Paste your API key into the form under Credentials, and make sure to **select the Project that will be associated to this provider**.
64+
It is possible to add multiple keys from the same provider.
6265

6366
#### Use Built-in Providers
64-
Go to the Billing page, add a payment method, and purchase $15 in credits to activate built-in providers. This gives you single-key access to all available models from OpenAI, Anthropic, Google Vertex, AWS Bedrock, and Groq.
67+
68+
Go to the [Billing page](https://gateway.pydantic.dev/admin/billing), add a payment method, and purchase $15 in credits to activate built-in providers.
69+
This gives you single-key access to all available models from OpenAI, Anthropic, Google Vertex, AWS Bedrock, and Groq.
6570

6671
### Grant access to your team
72+
6773
On the [Users](https://gateway.pydantic.dev/admin/users) page, create an invitation and share the URL with your team to allow them to access the project.
6874

6975
### Create Gateway project keys
70-
On the Keys page, Admins can create project keys which are not affected by spending limits. Users can only create personal keys, that will inherit spending caps from both User and Project levels, whichever is more restrictive.
76+
77+
On the Keys page, Admins can create project keys which are not affected by spending limits.
78+
Users can only create personal keys, that will inherit spending caps from both User and Project levels, whichever is more restrictive.
7179

7280
## Usage
81+
7382
After setting up your account with the instructions above, you will be able to make an AI model request with the Pydantic AI Gateway.
7483
The code snippets below show how you can use PAIG with different frameworks and SDKs.
7584
You can add `gateway/` as prefix on every known provider that
@@ -87,6 +96,7 @@ Examples of providers and models that can be used are:
8796
| AWS Bedrock | `bedrock` | `gateway/bedrock:amazon.nova-micro-v1:0` |
8897

8998
### Pydantic AI
99+
90100
Before you start, make sure you are on version 1.16 or later of `pydantic-ai`. To update to the latest version run:
91101

92102
=== "uv"
@@ -123,6 +133,7 @@ The first known use of "hello, world" was in a 1974 textbook about the C program
123133

124134

125135
### Claude Code
136+
126137
Before you start, log out of Claude Code using `/logout`.
127138

128139
Set your gateway credentials as environment variables:
@@ -174,3 +185,16 @@ response = client.messages.create(
174185
print(response.content[0].text)
175186
#> Hello user
176187
```
188+
189+
## Troubleshooting
190+
191+
### Unable to calculate spend
192+
193+
The gateway needs to know the cost of the request in order to provide insights about the spend, and to enforce spending limits.
194+
If it's unable to calculate the cost, it will return a 400 error with the message "Unable to calculate spend".
195+
196+
When [configuring a provider](https://gateway.pydantic.dev/admin/providers/new), you need to decide if you want the gateway to block
197+
the API key if it's unable to calculate the cost. If you choose to block the API key, any further requests using that API key will fail.
198+
199+
We are actively working on supporting more providers, and models.
200+
If you have a specific provider that you would like to see supported, please let us know on [Slack](https://logfire.pydantic.dev/docs/join-slack/) or [open an issue on `genai-prices`](https://github.com/pydantic/genai-prices/issues/new).

tests/test_temporal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ def workflow_raises(exc_type: type[Exception], exc_message: str) -> Iterator[Non
158158

159159
@pytest.fixture(scope='module')
160160
async def temporal_env() -> AsyncIterator[WorkflowEnvironment]:
161-
async with await WorkflowEnvironment.start_local(port=TEMPORAL_PORT, ui=True) as env: # pyright: ignore[reportUnknownMemberType]
161+
async with await WorkflowEnvironment.start_local( # pyright: ignore[reportUnknownMemberType]
162+
port=TEMPORAL_PORT,
163+
ui=True,
164+
dev_server_extra_args=['--dynamic-config-value', 'frontend.enableServerVersionCheck=false'],
165+
) as env:
162166
yield env
163167

164168

0 commit comments

Comments
 (0)