Skip to content

Conversation

@Kludex
Copy link
Member

@Kludex Kludex commented Nov 6, 2025

Note

Adds optional routing_group and profile params to gateway_provider that set corresponding Gateway headers; includes tests.

  • Gateway Provider (pydantic_ai/providers/gateway.py)
    • Add optional routing_group and profile parameters across overloads and implementation.
    • Set HTTP headers pydantic-ai-gateway-routing-group and pydantic-ai-gateway-profile when provided.
    • Update docstring to document new params and behavior.
  • Tests (tests/providers/test_gateway.py)
    • Add tests validating headers for routing_group and profile.
    • Keep existing provider initialization and routing behavior unchanged.

Written by Cursor Bugbot for commit 5a757e2. This will update automatically on new commits. Configure here.

@Kludex Kludex changed the title feat(gateway): support api_type feat(gateway): support profile and routing_group Nov 6, 2025
@Kludex Kludex changed the base branch from main to support-api-type November 6, 2025 22:57
@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Docs Preview

commit: 5a757e2
Preview URL: https://5a16fac7-pydantic-ai-previews.pydantic.workers.dev

Base automatically changed from support-api-type to main November 10, 2025 09:31
@Kludex Kludex marked this pull request as ready for review November 10, 2025 09:32
@Kludex Kludex enabled auto-merge (squash) November 10, 2025 09:32
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 9

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

http_client.headers.setdefault('pydantic-ai-gateway-profile', profile)

if routing_group is not None:
http_client.headers.setdefault('pydantic-ai-gateway-routing-group', routing_group)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Cached Client Headers: Stale Values Persist

Using setdefault to add profile and routing_group headers causes incorrect behavior when the cached HTTP client is reused. Since cached_async_http_client returns the same client instance for the same api_type, subsequent calls with different profile or routing_group values won't update the headers because setdefault only sets values for keys that don't exist. This means the second call will incorrectly use headers from the first call instead of the newly specified values.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair.

@Kludex Kludex merged commit 889abfb into main Nov 10, 2025
33 checks passed
@Kludex Kludex deleted the support-profile branch November 10, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants