{"id":50420075,"url":"https://github.com/robotdad/amplifier-module-provider-openai-chatgpt","last_synced_at":"2026-05-31T08:02:15.935Z","repository":{"id":353706958,"uuid":"1218363088","full_name":"robotdad/amplifier-module-provider-openai-chatgpt","owner":"robotdad","description":"ChatGPT subscription auth provider module for Amplifier - raw httpx + manual SSE against chatgpt.com/backend-api","archived":false,"fork":false,"pushed_at":"2026-04-25T04:52:05.000Z","size":150,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-25T06:25:30.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robotdad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-22T19:55:38.000Z","updated_at":"2026-04-25T04:52:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/robotdad/amplifier-module-provider-openai-chatgpt","commit_stats":null,"previous_names":["robotdad/amplifier-module-provider-openai-chatgpt"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/robotdad/amplifier-module-provider-openai-chatgpt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2Famplifier-module-provider-openai-chatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2Famplifier-module-provider-openai-chatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2Famplifier-module-provider-openai-chatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2Famplifier-module-provider-openai-chatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robotdad","download_url":"https://codeload.github.com/robotdad/amplifier-module-provider-openai-chatgpt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2Famplifier-module-provider-openai-chatgpt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33723549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-31T08:02:15.144Z","updated_at":"2026-05-31T08:02:15.929Z","avatar_url":"https://github.com/robotdad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Amplifier ChatGPT Subscription Provider Module\n\nChatGPT subscription auth provider for [Amplifier](https://github.com/microsoft/amplifier) -- uses raw HTTP + manual SSE against the ChatGPT backend API (`chatgpt.com/backend-api/codex/responses`).\n\n## Prerequisites\n\n- Python 3.11+\n- [UV](https://docs.astral.sh/uv/) package manager\n- A ChatGPT Plus/Pro/Team subscription with device code auth enabled in ChatGPT security settings\n\n## Purpose\n\nConnects Amplifier to the ChatGPT backend API using OAuth device code authentication. This is a separate module from `provider-openai` because the ChatGPT backend is a distinct, undocumented API surface that rejects many standard OpenAI API parameters and requires raw HTTP + manual SSE parsing (the OpenAI Python SDK's streaming accumulator does not work against it).\n\n## Contract\n\n| Field | Value |\n|-------|-------|\n| Module Type | Provider |\n| Mount Point | `providers` |\n| Entry Point | `amplifier_module_provider_openai_chatgpt:mount` |\n\n## Configuration\n\n```toml\n[providers.provider-openai-chatgpt]\ndefault_model = \"gpt-5.5\"\n```\n\n### All Config Options\n\n| Key | Type | Default | Description |\n|-----|------|---------|-------------|\n| `default_model` | str | `\"gpt-5.5\"` | Model to use for inference |\n| `raw` | bool | `false` | Include full request/response payloads in `llm:request`/`llm:response` hook events (for debugging) |\n| `login_on_mount` | bool | `true` | Trigger interactive device code login if tokens are absent or expired. Set `false` for non-interactive environments. |\n| `token_file_path` | str | `~/.amplifier/openai-chatgpt-oauth.json` | Path to the OAuth token JSON file |\n| `timeout` | float | `300.0` | HTTP timeout in seconds for streaming requests |\n| `models_cache_ttl` | float | `3600` | How long (seconds) to cache the live model catalog before re-fetching |\n\n### Authentication\n\nOn first use, the provider initiates an OAuth device code flow:\n\n1. Displays a verification URL (`https://auth.openai.com/codex/device`) and a code in the terminal\n2. You open the URL in a browser and enter the code\n3. Tokens are cached to `~/.amplifier/openai-chatgpt-oauth.json` for subsequent use\n\nTokens auto-refresh silently when they expire. If the refresh token itself expires, the device code flow runs again.\n\nRequires \"Sign in with device code\" to be enabled in your ChatGPT account security settings (Settings \u003e Security).\n\nWorks in SSH/headless sessions -- the device code flow only requires a browser on any device, not the machine running Amplifier.\n\n## Features\n\n- OAuth device code authentication with PKCE (no API key needed)\n- Raw httpx + manual SSE streaming (not the OpenAI SDK)\n- Automatic token refresh with 4-step fallback chain\n- Dynamic model catalog from live API (cached, with fallback)\n- Subscription plan type detection from OAuth JWT\n- Tool calling support\n- Reasoning effort support (`low`/`medium`/`high`/`xhigh` on all gpt-5.x models)\n- `-fast` model suffix support (e.g. `gpt-5.5-fast` -\u003e `gpt-5.5` with `service_tier: \"priority\"`)\n- Production routing matrix for all 13 Amplifier agent roles\n- `llm:request`/`llm:response` hook events with optional raw payload inclusion\n\n## Local Development\n\n```bash\n# Clone\ngit clone https://github.com/microsoft/amplifier-module-provider-openai-chatgpt.git\ncd amplifier-module-provider-openai-chatgpt\n\n# Install deps (including dev group: amplifier-core, pytest, ruff)\nuv sync\n\n# Run tests\nuv run pytest tests/ -v\n\n# Run a specific test file\nuv run pytest tests/test_sse.py -v\n\n# Lint and format check\nuv run ruff check .\nuv run ruff format --check .\n```\n\n### Testing with Amplifier\n\nRegister the module, install it, and add it through the standard provider management flow:\n\n```bash\n# 1. Register the module source\namplifier module add provider-openai-chatgpt \\\n  --source /path/to/amplifier-module-provider-openai-chatgpt\n\n# 2. Install the provider\namplifier provider install openai-chatgpt --force\n\n# 3. Add and configure via the interactive wizard\namplifier provider add openai-chatgpt\n\n# 4. Or use the management dashboard\namplifier provider manage\n```\n\nYou can also wire it into a bundle directly with an inline `source:` field:\n\n```markdown\n---\nbundle:\n  name: test-openai-chatgpt\n  version: 0.1.0\n\nincludes:\n  - bundle: git+https://github.com/microsoft/amplifier-foundation@main\n\nproviders:\n  - module: provider-openai-chatgpt\n    source: /path/to/amplifier-module-provider-openai-chatgpt\n    config:\n      default_model: gpt-5.5\n---\n\n# Test: provider-openai-chatgpt\n```\n\n```bash\namplifier run --bundle ./test-chatgpt.md \"Hello, can you hear me?\"\n```\n\n## Routing Matrix\n\nThis module ships with a production routing matrix at `routing/openai-chatgpt.yaml` that maps all 13 Amplifier agent roles to the correct models. This is **required** for agent delegation to work -- without it, agents like `web-research`, `explorer`, and `zen-architect` will fail to resolve a provider.\n\nTo use it:\n\n```bash\n# Copy to your user routing directory\ncp routing/openai-chatgpt.yaml ~/.amplifier/routing/\n\n# Activate it\namplifier routing use openai-chatgpt\n\n# Verify\namplifier routing show\n```\n\nThe matrix uses two-tier fallback chains (gpt-5.5 -\u003e gpt-5.4) so it works across subscription tiers. Role highlights:\n\n| Role | Primary Model | Config |\n|------|--------------|--------|\n| `general`, `creative`, `writing`, `vision` | gpt-5.5 | -- |\n| `fast` | gpt-?.?-mini* (glob) | -- |\n| `coding` | gpt-?.?-codex* (glob) | -- |\n| `reasoning`, `research`, `security-audit`, `critical-ops` | gpt-5.5 | `reasoning_effort: high` |\n| `critique` | gpt-5.5 | `reasoning_effort: xhigh` |\n\nSee the matrix YAML header for full documentation on glob strategy, fallback philosophy, and differences from the standard `openai` routing matrix.\n\n## Supported Models\n\nThe model catalog is fetched dynamically from the ChatGPT backend API at `GET /backend-api/codex/models`. Available models depend on your subscription tier. The catalog is cached for 1 hour (configurable via `models_cache_ttl`).\n\nExample catalog for a **Plus** subscription (as of April 2026):\n\n| Model | Context Window | Priority | Speed Tiers | Reasoning |\n|-------|---------------|----------|-------------|-----------|\n| gpt-5.5 | 272K | 0 (highest) | fast | low/med/high/xhigh |\n| gpt-5.4 | 272K | 2 | fast | low/med/high/xhigh |\n| gpt-5.4-mini | 272K | 4 | -- | low/med/high/xhigh |\n| gpt-5.3-codex | 272K | 6 | -- | low/med/high/xhigh |\n| gpt-5.2 | 272K | 10 | -- | low/med/high/xhigh |\n\nModels with a \"fast\" speed tier support a `-fast` suffix (e.g. `gpt-5.5-fast`) which maps to `service_tier: \"priority\"` in the request. This consumes priority quota faster.\n\nIf the live API is unreachable, a minimal fallback catalog (gpt-5.2, gpt-5.2-codex, gpt-4o) is used. The fallback is not cached, so the next `list_models()` call retries the live API.\n\n## DTU Validation\n\nThis module includes a [Digital Twin Universe](https://github.com/microsoft/amplifier-bundle-digital-twin-universe) profile for end-to-end validation in an isolated container. The DTU environment provisions Amplifier with the provider, a pre-authenticated OAuth token, and the routing matrix -- then runs acceptance tests against the live ChatGPT backend API.\n\n```bash\n# Launch (requires Incus and a valid OAuth token on the host)\namplifier-digital-twin launch \\\n  .amplifier/digital-twin-universe/profiles/chatgpt-provider-reality-check.yaml \\\n  --var OAUTH_TOKEN_FILE=$HOME/.amplifier/openai-chatgpt-oauth.json\n\n# Check readiness\namplifier-digital-twin check-readiness \u003cid\u003e\n\n# Destroy when done\namplifier-digital-twin destroy \u003cid\u003e\n```\n\nSee [docs/DTU_VALIDATION.md](docs/DTU_VALIDATION.md) for the full guide covering prerequisites, what's tested, what's excluded, and troubleshooting.\n\n## Known Limitations\n\n- **Automatic mid-session 401 recovery** -- if the access token expires mid-session, the provider performs one silent token refresh and retries the request automatically. A second consecutive 401 raises `AuthenticationError`.\n- **No `response.incomplete` continuation** -- if a reasoning model hits its output limit, the partial response is lost. Auto-continuation is planned.\n- **Streaming is mandatory** -- the ChatGPT backend requires `stream=True`. The provider always streams internally but returns a complete `ChatResponse` to the orchestrator.\n- **No `response.content_part.delta` handling** -- only `response.output_item.done` events are accumulated. Streaming delta forwarding is planned.\n\n## Dependencies\n\n- `httpx` - HTTP client for raw API requests\n\n## Contributing\n\n\u003e [!NOTE]\n\u003e This project is not currently accepting external contributions, but we're actively working toward opening this up. We value community input and look forward to collaborating in the future. For now, feel free to fork and experiment!\n\nMost contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit [Contributor License Agreements](https://cla.opensource.microsoft.com).\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft\ntrademarks or logos is subject to and must follow\n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobotdad%2Famplifier-module-provider-openai-chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobotdad%2Famplifier-module-provider-openai-chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobotdad%2Famplifier-module-provider-openai-chatgpt/lists"}