feat: add Codex AI proxy credential fallback#865
Merged
simple-agent-manager[bot] merged 8 commits intomainfrom May 1, 2026
Merged
feat: add Codex AI proxy credential fallback#865simple-agent-manager[bot] merged 8 commits intomainfrom
simple-agent-manager[bot] merged 8 commits intomainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When no user-provided OpenAI API key exists for openai-codex agent type, inject SAM's AI proxy as the credential source. Mirrors the Claude Code fallback (WP2, PR #862) for the OpenAI agent type. - Add DEFAULT_AI_PROXY_OPENAI_MODEL constant (gpt-4.1) - Extend runtime.ts proxy fallback to include openai-codex - Add openai-proxy provider branch in session_host.go - Inject OPENAI_BASE_URL and OPENAI_API_KEY env vars for Codex Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Mirrors the Claude Code proxy fallback test suite for openai-codex: - Returns openai-proxy inferenceConfig when no credential exists - User credential takes priority over proxy fallback - 404 when AI proxy is disabled - Custom model via AI_PROXY_DEFAULT_OPENAI_MODEL env var - Task credential source tracking - No regression on opencode or claude-code fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address review findings: move PROXY_ELIGIBLE_AGENTS to module scope for isolate reuse, add comment documenting KV model-picker gap for Codex (intentional, matches Claude Code pattern). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Captures defense-in-depth findings from WP3 security audit: - Short-lived proxy-scoped tokens - __platform_proxy__ sentinel cleanup - BaseURL origin validation - Go-side proxy injection tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
simple-agent-manager Bot
added a commit
that referenced
this pull request
May 1, 2026
* chore: move task to active Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: wire AI proxy Anthropic route to Unified Billing (#865) Replace resolveAnthropicApiKey() with resolveUpstreamAuth() in the Anthropic proxy, enabling Cloudflare Unified Billing via cf-aig-authorization header. Add CF_API_TOKEN as fallback for CF_AIG_TOKEN. Update OpenAI-compat proxy for consistent billing resolution. Remove unused resolveAnthropicApiKey from ai-proxy-shared. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: update CLAUDE.md for unified billing changes Update anthropic-proxy-endpoint and ai-proxy-gateway entries to reflect resolveUpstreamAuth() usage and CF_API_TOKEN fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: sort imports in ai-proxy.ts for lint compliance Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * task: archive ai-proxy-anthropic-unified-billing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: address cloudflare-specialist review findings - Add log.warn when falling back to CF_API_TOKEN (high-privilege token) - Add cf-aig-metadata header to count_tokens endpoint for analytics Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: sanitize error messages from resolveUpstreamAuth Log full error details server-side, return generic message to clients. Prevents leaking internal variable names (CF_AIG_TOKEN, CF_API_TOKEN) in 503 responses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: add billing header contract integration tests Verify UpstreamAuth headers are correctly assembled for unified and platform-key modes, mutual exclusivity of auth headers, metadata always present, and error message sanitization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove unused vi import from billing integration tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Raphaël Titsworth-Morin <raphael@raphaeltm.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.


Summary
openai-codexagent type, inject SAM's AI proxy as the credential source for zero-key onboardingprovider: 'openai-proxy'withbaseURL: https://api.{domain}/ai/v1OPENAI_BASE_URL,OPENAI_API_KEY(callback token), and optionallyOPENAI_MODELenv vars into the Codex containergpt-4.1, configurable viaAI_PROXY_DEFAULT_OPENAI_MODELenv varChanges
packages/shared/src/constants/ai-services.ts— newDEFAULT_AI_PROXY_OPENAI_MODELconstantapps/api/src/env.ts— addedAI_PROXY_DEFAULT_OPENAI_MODELenv var typeapps/api/src/routes/workspaces/runtime.ts— extended proxy fallback to includeopenai-codexwithopenai-proxyproviderpackages/vm-agent/internal/acp/session_host.go— added Codex env var injection branchapps/api/.env.example— documented new env varValidation
pnpm lintpnpm typecheckpnpm test(pre-existing ButtonGroup test failure unrelated)pnpm buildStaging Verification (REQUIRED for all code changes — merge-blocking)
app.sammy.partyusing test credentialsStaging Verification Evidence
app.sammy.partyvia token-login{"status":"healthy"}atapi.sammy.party/healthUI Compliance Checklist (Required for UI changes)
N/A: no UI changes
End-to-End Verification (Required for multi-component changes)
Data Flow Trace
POST /api/workspaces/:id/agent-keywithagentType: 'openai-codex'→
apps/api/src/routes/workspaces/runtime.tsagent-key handler→
runtime.ts:81checksPROXY_ELIGIBLE_AGENTS.has('openai-codex')→ trueinferenceConfig: { provider: 'openai-proxy', baseURL: 'https://api.{domain}/ai/v1', model: 'gpt-4.1' }→
runtime.ts:95-108agentType == "openai-codex" && provider == "openai-proxy"→
packages/vm-agent/internal/acp/session_host.go:1008-1020OPENAI_BASE_URL,OPENAI_API_KEY(callback token),OPENAI_MODELinto container env{OPENAI_BASE_URL}/chat/completions→ SAM's AI proxyUntested Gaps
Go-side injection branch has no automated test (pre-existing gap — same for claude-code branch). TypeScript tests cover the full API response shape. Backlog task filed:
tasks/backlog/2026-05-01-ai-proxy-credential-hardening.md.Post-Mortem (Required for bug fix PRs)
N/A: not a bug fix
Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human — all completedExceptions (If any)
tasks/backlog/2026-05-01-ai-proxy-credential-hardening.mdAgent Preflight (Required)
Classification
External References
N/A: mirrors existing claude-code proxy pattern (PR #862). No new external API integration.
Codebase Impact Analysis
packages/shared— new constantDEFAULT_AI_PROXY_OPENAI_MODELapps/api— extended agent-key fallback inruntime.ts, new env var inenv.tspackages/vm-agent— new injection branch insession_host.goDocumentation & Specs
apps/api/.env.example— addedAI_PROXY_DEFAULT_OPENAI_MODELCLAUDE.md— no update needed (AI proxy gateway entry already covers the pattern)Constitution & Risk Check
gpt-4.1is configurable viaAI_PROXY_DEFAULT_OPENAI_MODELenv var with shared constant fallbackBASE_DOMAINenv var