Repository navigation
Conversation
Some API proxies and gateways filter requests based on the User-Agent header (e.g. blocking the OpenAI SDK's default "OpenAI/Python ..."), which makes sgpt fail with PermissionDeniedError even though the same request succeeds via curl. Add an OPENAI_USER_AGENT config option (also available as an environment variable). When set to anything other than "default", it is passed to the OpenAI client via default_headers. The default value keeps the SDK's built-in User-Agent, so existing behavior is unchanged.
guohai
force-pushed
the
feature/configurable-user-agent
branch
from
August 28, 2026 08:44
7ea9594 to
401d7e5
Compare
This branch has not been deployed
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
Some API proxies and gateways filter requests by the
User-Agentheader. For example, a gateway may return403for any request whose UA matchesOpenAI/Python*— the OpenAI SDK's default — while the identical request body succeeds viacurl. In that case sgpt fails with:Since the OpenAI SDK provides no environment variable to override its
User-Agent, sgpt users behind such gateways currently have no workaround short of patching site-packages.Changes
OPENAI_USER_AGENTin~/.config/shell_gpt/.sgptrc(also usable as an environment variable, like other options)."default", which keeps the OpenAI SDK's built-inUser-Agent— behavior is unchanged for existing users.OpenAIclient viadefault_headers={"User-Agent": ...}(follows the same pattern asAPI_BASE_URL).Testing
pytest(29 passed),black --check,isort --check-only,mypy, andruffall pass.OPENAI_USER_AGENT=defaultthe request is rejected with 403; with a custom value the request succeeds.