Skip to content

[Bug]: Pre-flight validation fails for ChatGPT subscription profiles with "Incorrect API key provided: None" #4896

Closed

Description

@neubig

Bug Description

When a user connects their ChatGPT subscription (via OAuth device-code flow) and then tries to save an LLM profile using a subscription model (e.g. gpt-6-astra), the pre-flight validation fails with:

litellm.AuthenticationError: AuthenticationError: OpenAIException - {
  "error": {
    "message": "Incorrect API key provided: None. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

Root Cause

The validate_profile endpoint in openhands-agent-server/openhands/agent_server/profiles_router.py deserializes the submitted LLM config via plain Pydantic but never calls create_subscription_llm_from_config() — unlike LLM.from_persisted() which does.

When the frontend sends a new subscription profile config, it sets auth_type: "subscription" and subscription_vendor: "openai", but the OAuth access token lives in the credential store (~/.openhands/auth/openai_oauth.json), not in the serialized LLM config. Without create_subscription_llm_from_config, the LLM's is_subscription flag stays False and _subscription_credentials stays None, so litellm sends api_key=None to OpenAI.

The save path (to_persisted → from_persisted) correctly handles this, but the pre-flight validation path does not.

Expected Behavior

The pre-flight validation should resolve OAuth credentials from the credential store for subscription profiles, so the 1-token ping completion succeeds.

Actual Behavior

Reproduced with uv run python3 -c "..." against the agent-server started via uv tool uvx ... agent-server:

# Start the agent-server (software-agent-sdk main)
uv tool uvx --reinstall \
  --from openhands-agent-server \
  --with-editable openhands-sdk \
  --with-editable openhands-tools \
  --with-editable openhands-workspace \
  agent-server --host 127.0.0.1 --port 18000

# After connecting ChatGPT subscription via OAuth, the pre-flight
# POST /api/profiles/{name}/validate sends api_key=None and fails:
#   litellm.AuthenticationError: Incorrect API key provided: None

The pre-flight sends api_key=None and fails with AuthenticationError.

Steps to Reproduce

  1. Start the agent-server with software-agent-sdk from main
  2. Connect a ChatGPT subscription via the OpenHands UI (OAuth device-code flow)
  3. Try to save a new LLM profile with model gpt-6-astra and auth type "subscription"
  4. The pre-flight validation fails with the Incorrect API key provided: None error

Acceptance Criteria

  • Pre-flight validation (POST /api/profiles/{name}/validate) resolves OAuth credentials for subscription profiles
  • Saving a ChatGPT subscription profile succeeds without authentication errors
  • Unit test covers the subscription pre-flight path

Activity

  1. added
    bug
    llm
    priority:high
    ready-for-dev
    on Sep 8, 2026
  2. removed
    ready-for-dev
    on Sep 8, 2026
  3. github-actions commented on Sep 8, 2026

    @github-actions
    Contributor

    ✅ ready-for-dev label applied

    This issue meets the readiness criteria and is ready for contribution.
    A contributor can now open a PR that links this issue (Fixes #<number>).

    This is an automated check — no AI was used to generate this comment.

  4. added
    ready-for-dev
    on Sep 8, 2026
  5. added
    ready-for-dev
    and removed
    ready-for-dev
    on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugllmpriority:highready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions