Skip to content

fix(heroku): avoid duplicating /v1 in base_url#6142

Merged
DouweM merged 2 commits into
pydantic:mainfrom
VectorPeak:codex/heroku-base-url-v1
Jun 30, 2026
Merged

fix(heroku): avoid duplicating /v1 in base_url#6142
DouweM merged 2 commits into
pydantic:mainfrom
VectorPeak:codex/heroku-base-url-v1

Conversation

@VectorPeak

@VectorPeak VectorPeak commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This fixes HerokuProvider base URL normalization when the configured Heroku inference URL already includes /v1.

What Problem This Solves

HerokuProvider stripped trailing slashes and always appended /v1:

base_url = base_url.rstrip('/') + '/v1'

That works for the default https://us.inference.heroku.com, but it turns an already-normalized OpenAI-compatible endpoint into a malformed double-version path:

https://us.inference.heroku.com/v1  -> https://us.inference.heroku.com/v1/v1/
https://us.inference.heroku.com/v1/ -> https://us.inference.heroku.com/v1/v1/

Users may naturally pass a /v1 endpoint through HerokuProvider(base_url=...) or HEROKU_INFERENCE_URL, since Heroku Managed Inference exposes OpenAI-compatible /v1/... API paths.

Change

  • Normalize the Heroku base URL once.
  • Append /v1 only when the configured base URL does not already end with /v1.
  • Add a regression test covering base URLs with and without /v1, with and without a trailing slash.

Evidence

Before this change, local reproduction showed:

https://us.inference.heroku.com/v1  -> https://us.inference.heroku.com/v1/v1/
https://us.inference.heroku.com/v1/ -> https://us.inference.heroku.com/v1/v1/

After this change, all supported inputs normalize to:

https://us.inference.heroku.com/v1/

Reference: Heroku Managed Inference documents OpenAI-compatible /v1 API endpoints.

Validation

  • uv run pytest tests/providers/test_heroku.py::test_heroku_provider_normalizes_base_url
  • uv run ruff check pydantic_ai_slim/pydantic_ai/providers/heroku.py tests/providers/test_heroku.py
  • uv run ruff format --check pydantic_ai_slim/pydantic_ai/providers/heroku.py tests/providers/test_heroku.py
  • git diff --check

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • PR title is fit for the release changelog.

Review in cubic

@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) bug Report that something isn't working, or PR implementing a fix labels Jun 30, 2026
@DouweM
DouweM merged commit 4d6ec80 into pydantic:main Jun 30, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: S Small PR (≤100 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants