Skip to content

Answer on a plain OpenAI key or an Anthropic key from the Pydantic AI Bot - #662

Merged
davidmckayv merged 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/pydantic-ai-bot-blank-urls
Sep 28, 2026
Merged

davidmckayv merged 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/pydantic-ai-bot-blank-urls

Conversation

@asasemahmed

Copy link
Copy Markdown
Contributor

What this changes

Picked with either a plain OpenAI key or an Anthropic key, the Pydantic AI Bot fails every run.

Compose writes the endpoint a model choice does not need as empty: the picked harness gets
OPENAI_BASE_URL: ${OPENAI_CONTAINER_BASE_URL:-${OPENAI_BASE_URL:-}} and
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-}, so a plain OpenAI key arrives with
OPENAI_BASE_URL="" and an Anthropic key with ANTHROPIC_BASE_URL="". Agent("openai:…") and
Agent("anthropic:…") build their providers with no base_url, so each SDK reads its variable
itself and falls back to its official endpoint only when the variable is absent. Given "", the
request has no host.

The Bot now removes an empty OPENAI_BASE_URL or ANTHROPIC_BASE_URL before it builds the model,
and strips a real one, which is what _normalize_openai_base_url in agent-langgraph-agui already
does. A real endpoint, an OpenAI-compatible one included, is unchanged.

#649 edits the provider and model lines of this file; this change is a separate hunk below them.

Where it runs

  • New state that outlives a request? None. The environment is read once at import.
  • What happens on the second replica? The same, from the same environment.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: nothing on the server changes, and the
    harness still refuses a request without the server's token.
  • New refusals and new failures each write a row: none added.
  • Nothing new is trusted from the client.

Changelog

  • An entry in CHANGELOG.md under Unreleased.

Proof

  • New test_a_key_reaches_the_official_endpoint_when_compose_leaves_the_url_blank, for both keys:
    the real Pydantic AI and SDK clients with only the transport replaced (on httpx2 as well as
    httpx, since the OpenAI SDK sends through httpx2), routed into this file's fake provider. It
    asserts https://api.openai.com/v1/responses and https://api.anthropic.com/v1/messages
    respectively, and a finished run.
  • Python 3.12, the CI step's commands, run in a container with no network: this branch
    9 passed. With src from main: 2 failed, 7 passed, both new cases.
  • Versions pip resolved: pydantic-ai-slim 2.51.0, openai 3.19.2, anthropic 1.8.0,
    httpx2 2.13.1.
  • Not run: a real key, and the published image.

… Bot

Compose writes the endpoint a model choice does not need as empty:
OPENAI_BASE_URL for a plain OpenAI key, ANTHROPIC_BASE_URL for an
Anthropic key. Pydantic AI builds each provider's client from the
environment, and the SDKs only default an absent URL, so both choices
failed every run. The Bot now removes an empty value before building
the model, as agent-langgraph-agui already does.
@davidmckayv
davidmckayv merged commit 093dc24 into CopilotKit:main Sep 28, 2026
17 checks passed
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