Skip to content

Answer on a plain OpenAI key from the AG2 Bot - #661

Merged
davidmckayv merged 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/ag2-bot-blank-openai-url
Sep 28, 2026
Merged

davidmckayv merged 1 commit into
CopilotKit:mainfrom
asasemahmed:fix/ag2-bot-blank-openai-url

Conversation

@asasemahmed

Copy link
Copy Markdown
Contributor

What this changes

Picked with a plain OpenAI key, the AG2 Bot fails every run. Compose passes the picked harness
OPENAI_BASE_URL: ${OPENAI_CONTAINER_BASE_URL:-${OPENAI_BASE_URL:-}}, and for a plain OpenAI key
that is empty. OpenAIConfig(model=model) leaves base_url as None, so the OpenAI SDK reads
OPENAI_BASE_URL itself, and it falls back to https://api.openai.com/v1 only when that is absent.
Given "", the request has no host.

The Anthropic branch just above already handles exactly this: "Compose exports missing overrides as
""; the SDK only defaults an absent URL." The OpenAI branch now does the same, passing
base_url=(OPENAI_BASE_URL or "").strip() or "https://api.openai.com/v1". An OpenAI-compatible
endpoint is passed through as before.

#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 config is chosen 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_an_openai_key_uses_the_official_endpoint_when_compose_sets_a_blank_url, the twin of
    the Anthropic test above it: the real AG2 and OpenAI clients, with only the httpx2 transport
    replaced and routed into this file's fake provider. It asserts the request went to
    https://api.openai.com/v1/chat/completions with Bearer test-key, and a finished run.
  • Python 3.12, the CI step's commands, run in a container with no network: this branch
    6 passed. With src from main: 1 failed, 5 passed, the new case, whose request goes to a
    relative /chat/completions.
  • Versions pip resolved: ag2 1.1.0, openai 3.19.2, anthropic 1.8.0, httpx2 2.13.1.
  • Not run: a real OpenAI key, and the published image.

Compose writes OPENAI_BASE_URL empty when the model screen chose a
plain OpenAI key, and the OpenAI SDK only defaults an absent URL, so
the Bot's client was given "" as its address and every run failed. It
now falls back to https://api.openai.com/v1 for an empty value, as its
Anthropic branch already does for ANTHROPIC_BASE_URL.
@davidmckayv
davidmckayv merged commit 2afaadb 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