-
Notifications
You must be signed in to change notification settings - Fork 12
docs: Add LLM subscriptions guide for OpenAI ChatGPT subscription authentication #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5964f92
docs: Add LLM subscriptions guide for OpenAI ChatGPT subscription aut…
openhands-agent 06c8e36
docs: Update subscription login example path and add critic documenta…
openhands-agent 7189de6
Merge main into feat/openai-subscription-auth
openhands-agent 82dfabf
docs: Update LLM subscriptions guide and add ChatGPT login option to …
openhands-agent 352e37f
Apply suggestion from @xingyaoww
xingyaoww 199bb1e
docs: Simplify ChatGPT subscription option to Tip with link
openhands-agent 295f84c
docs: Refactor llm-subscriptions.mdx to follow guide format
openhands-agent 8cfc38a
docs: Simplify llm-subscriptions.mdx - remove technical details
openhands-agent af1e7bb
docs: Add ChatGPT subscription option to getting-started and update A…
openhands-agent 6e24e01
Merge branch 'main' into feat/openai-subscription-auth
xingyaoww 50ee2b3
Update sdk/guides/llm-subscriptions.mdx
xingyaoww File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| --- | ||
| title: LLM Subscriptions | ||
| description: Use your ChatGPT Plus/Pro subscription to access Codex models without consuming API credits. | ||
| --- | ||
|
|
||
| import RunExampleCode from "/sdk/shared-snippets/how-to-run-example.mdx"; | ||
|
|
||
| <Info> | ||
| OpenAI subscription is the first provider we support. More subscription providers will be added in future releases. | ||
| </Info> | ||
|
|
||
| > A ready-to-run example is available [here](#ready-to-run-example)! | ||
|
|
||
| Use your existing ChatGPT Plus or Pro subscription to access OpenAI's Codex models without consuming API credits. The SDK handles OAuth authentication, credential caching, and automatic token refresh. | ||
|
|
||
| ## How It Works | ||
|
|
||
| <Steps> | ||
| <Step> | ||
| ### Call subscription_login() | ||
|
|
||
| The `LLM.subscription_login()` class method handles the entire authentication flow: | ||
|
|
||
| ```python icon="python" | ||
| from openhands.sdk import LLM | ||
|
|
||
| llm = LLM.subscription_login(vendor="openai", model="gpt-5.2-codex") | ||
| ``` | ||
|
|
||
| On first run, this opens your browser for OAuth authentication with OpenAI. After successful login, credentials are cached locally in `~/.openhands/auth/` for future use. | ||
| </Step> | ||
| <Step> | ||
| ### Use the LLM | ||
|
|
||
| Once authenticated, use the LLM with your agent as usual. The SDK automatically refreshes tokens when they expire. | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| ## Supported Models | ||
|
|
||
| The following models are available via ChatGPT subscription: | ||
|
|
||
| | Model | Description | | ||
| |-------|-------------| | ||
| | `gpt-5.2-codex` | Latest Codex model (default) | | ||
| | `gpt-5.2` | GPT-5.2 base model | | ||
| | `gpt-5.1-codex-max` | High-capacity Codex model | | ||
| | `gpt-5.1-codex-mini` | Lightweight Codex model | | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| ### Force Fresh Login | ||
|
|
||
| If your cached credentials become stale or you want to switch accounts: | ||
|
|
||
| ```python icon="python" | ||
| llm = LLM.subscription_login( | ||
| vendor="openai", | ||
| model="gpt-5.2-codex", | ||
| force_login=True, # Always perform fresh OAuth login | ||
| ) | ||
| ``` | ||
|
|
||
| ### Disable Browser Auto-Open | ||
|
|
||
| For headless environments or when you prefer to manually open the URL: | ||
|
|
||
| ```python icon="python" | ||
| llm = LLM.subscription_login( | ||
| vendor="openai", | ||
| model="gpt-5.2-codex", | ||
| open_browser=False, # Prints URL to console instead | ||
| ) | ||
| ``` | ||
|
|
||
| ### Check Subscription Mode | ||
|
|
||
| Verify that the LLM is using subscription-based authentication: | ||
|
|
||
| ```python icon="python" | ||
| llm = LLM.subscription_login(vendor="openai", model="gpt-5.2-codex") | ||
| print(f"Using subscription: {llm.is_subscription}") # True | ||
| ``` | ||
|
|
||
| ## Credential Storage | ||
|
|
||
| Credentials are stored securely in `~/.openhands/auth/`. To clear cached credentials and force a fresh login, delete the files in this directory. | ||
|
|
||
| ## Ready-to-run Example | ||
|
|
||
| <Note> | ||
| This example is available on GitHub: [examples/01_standalone_sdk/35_subscription_login.py](https://github.com/OpenHands/software-agent-sdk/blob/main/examples/01_standalone_sdk/35_subscription_login.py) | ||
| </Note> | ||
|
|
||
| ```python icon="python" expandable examples/01_standalone_sdk/35_subscription_login.py | ||
| """Example: Using ChatGPT subscription for Codex models. | ||
|
|
||
| This example demonstrates how to use your ChatGPT Plus/Pro subscription | ||
| to access OpenAI's Codex models without consuming API credits. | ||
|
|
||
| The subscription_login() method handles: | ||
| - OAuth PKCE authentication flow | ||
| - Credential caching (~/.openhands/auth/) | ||
| - Automatic token refresh | ||
|
|
||
| Supported models: | ||
| - gpt-5.2-codex | ||
| - gpt-5.2 | ||
| - gpt-5.1-codex-max | ||
| - gpt-5.1-codex-mini | ||
|
|
||
| Requirements: | ||
| - Active ChatGPT Plus or Pro subscription | ||
| - Browser access for initial OAuth login | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from openhands.sdk import LLM, Agent, Conversation, Tool | ||
| from openhands.tools.file_editor import FileEditorTool | ||
| from openhands.tools.terminal import TerminalTool | ||
|
|
||
|
|
||
| # First time: Opens browser for OAuth login | ||
| # Subsequent calls: Reuses cached credentials (auto-refreshes if expired) | ||
| llm = LLM.subscription_login( | ||
| vendor="openai", | ||
| model="gpt-5.2-codex", # or "gpt-5.2", "gpt-5.1-codex-max", "gpt-5.1-codex-mini" | ||
| ) | ||
|
|
||
| # Alternative: Force a fresh login (useful if credentials are stale) | ||
| # llm = LLM.subscription_login(vendor="openai", model="gpt-5.2-codex", force_login=True) | ||
|
|
||
| # Alternative: Disable auto-opening browser (prints URL to console instead) | ||
| # llm = LLM.subscription_login( | ||
| # vendor="openai", model="gpt-5.2-codex", open_browser=False | ||
| # ) | ||
|
|
||
| # Verify subscription mode is active | ||
| print(f"Using subscription mode: {llm.is_subscription}") | ||
|
|
||
| # Use the LLM with an agent as usual | ||
| agent = Agent( | ||
| llm=llm, | ||
| tools=[ | ||
| Tool(name=TerminalTool.name), | ||
| Tool(name=FileEditorTool.name), | ||
| ], | ||
| ) | ||
|
|
||
| cwd = os.getcwd() | ||
| conversation = Conversation(agent=agent, workspace=cwd) | ||
|
|
||
| conversation.send_message("List the files in the current directory.") | ||
| conversation.run() | ||
| print("Done!") | ||
| ``` | ||
|
|
||
| <RunExampleCode path_to_script="examples/01_standalone_sdk/35_subscription_login.py"/> | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - **[LLM Registry](/sdk/guides/llm-registry)** - Manage multiple LLM configurations | ||
| - **[LLM Streaming](/sdk/guides/llm-streaming)** - Stream responses token-by-token | ||
| - **[LLM Reasoning](/sdk/guides/llm-reasoning)** - Access model reasoning traces |
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
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.
Uh oh!
There was an error while loading. Please reload this page.