Python: Add GitHub Copilot BYOK sample#7336
Open
droideronline wants to merge 2 commits into
Open
Conversation
Demonstrates routing GitHubCopilotAgent requests through a custom OpenAI-compatible endpoint via ProviderConfig instead of the default GitHub Copilot backend.
droideronline
temporarily deployed
to
github-app-auth
July 26, 2026 17:49 — with
GitHub Actions
Inactive
droideronline
temporarily deployed
to
github-app-auth
July 26, 2026 17:49 — with
GitHub Actions
Inactive
droideronline
temporarily deployed
to
github-app-auth
July 26, 2026 17:49 — with
GitHub Actions
Inactive
droideronline
temporarily deployed
to
github-app-auth
July 26, 2026 17:49 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Python sample demonstrating how to use GitHubCopilotAgent with Copilot SDK BYOK (Bring Your Own Key) to route requests through a custom OpenAI/Azure/Anthropic-compatible endpoint, and documents it in the provider samples README.
Changes:
- Add
github_copilot_with_byok.pysample showing BYOK configuration viaGitHubCopilotOptions(provider=...)and environment variables. - Update the GitHub Copilot provider samples
README.mdto include the new sample in the examples table.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/samples/02-agents/providers/github_copilot/README.md | Adds the BYOK sample to the examples list for discoverability. |
| python/samples/02-agents/providers/github_copilot/github_copilot_with_byok.py | New end-to-end sample configuring BYOK provider routing and model selection via env vars. |
Comments suppressed due to low confidence (1)
python/samples/02-agents/providers/github_copilot/github_copilot_with_byok.py:41
- The sample hard-codes
type: "openai"while the docstring claims Azure OpenAI/Anthropic are supported, and it also passesmodel_idinsideProviderConfig(the repo’s existing ProviderConfig examples/tests only use keys liketype,base_url,api_key/bearer_token). This is likely to be rejected by the Copilot SDK or confuse users; keep the model selection atGitHubCopilotOptions(model=...)and let the providertypebe configurable.
"type": "openai",
"base_url": os.environ["BYOK_BASE_URL"],
"api_key": os.environ["BYOK_API_KEY"],
"wire_api": "completions",
"model_id": model_id,
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
droideronline
temporarily deployed
to
github-app-auth
July 26, 2026 17:59 — with
GitHub Actions
Inactive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
GitHub Copilot supports BYOK (Bring Your Own Key — https://docs.github.com/en/copilot/how-tos/copilot-sdk/auth/byok), letting requests be routed through a custom OpenAI/Azure/Anthropic-compatible endpoint instead of the default GitHub Copilot backend.
GitHubCopilotOptions.provideralready forwards aProviderConfigstraight through to the Copilot SDK, but there was no sample demonstrating the scenario end-to-end.Description & Review Guide
github_copilot_with_byok.pyunderpython/samples/02-agents/providers/github_copilot/, showing how to setGitHubCopilotOptions(model=..., provider=ProviderConfig(...))to route through a custom endpoint, readingBYOK_BASE_URL/BYOK_API_KEY/BYOK_MODEL_IDfrom the environment. Updates the folder'sREADME.mdtable to list the new sample.ProviderConfigfields used (type,base_url,api_key,wire_api,model_id) match current guidance, and whether the security note on static BYOK credentials is clear enough.Verified with
ruff check,ruff format --check, andpyright(all clean).Related Issue
Fixes #
Contribution Checklist