Skip to content

feat: select the credential profile with RUNPOD_PROFILE - #686

Open
deanq wants to merge 6 commits into
mainfrom
deanq/sls-971-profile-env
Open

deanq wants to merge 6 commits into
mainfrom
deanq/sls-971-profile-env

Conversation

@deanq

@deanq deanq commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

rp login --profile NAME saves a key under [NAME] in ~/.runpod/config.toml. Nothing read that profile back, though: runpod.profile was fixed to "default", so using the saved key meant setting runpod.profile in code or exporting RUNPOD_API_KEY.

RUNPOD_PROFILE now selects the profile, in the same way as AWS_PROFILE:

Before After
runpod.profile at import "default" RUNPOD_PROFILE, else "default"
rp login --profile default default RUNPOD_PROFILE, else default

Precedence is unchanged: RUNPOD_API_KEY > stored profile, and an explicit --profile > RUNPOD_PROFILE. An unset or blank RUNPOD_PROFILE behaves exactly as before.

RUNPOD_PROFILE=staging rp login     # saves to [staging]
RUNPOD_PROFILE=staging rp pod list  # uses the [staging] key

The CLI docs and getting-started docs now describe the variable. The getting-started guide also had the wrong credentials file (credentials.toml; the real file is config.toml) and claimed that setting runpod.profile in a script switches profiles, which it doesn't because the key is read at import; both are corrected. Renaming the file to getting_started.md is in #697, kept separate so the file's history follows the rename.

Test plan

  • New tests/test_profile.py covers the default, a selected profile, whitespace stripping, a blank value falling back to the default, loading the key from the selected profile, and RUNPOD_API_KEY still winning.
  • rp login tests check that the env var picks the profile it saves to, and that --profile overrides it.
  • The tests for new behavior failed before the change.
  • make quality-check: 2742 passed, 94.27% coverage.

rp login --profile NAME saved a key under [NAME], but runpod.profile was
fixed to "default", so the saved key was never used without code
changes. RUNPOD_PROFILE now selects the profile for runpod.api_key and
is the default for rp login --profile.

- unset or blank RUNPOD_PROFILE keeps the "default" profile
- an explicit --profile still overrides the env var
- RUNPOD_API_KEY still takes precedence over any stored profile
@deanq
deanq requested review from KAJdev and a balanced review from Copilot and removed request for Copilot November 6, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A profile containing only S3 credentials causes import runpod to raise KeyError when RUNPOD_API_KEY is unset, also blocking rp login from adding the missing key.

1 open issue
What changed in this PR

This PR lets the SDK and CLI select saved credentials through RUNPOD_PROFILE, avoiding the need to set the profile in Python code.

Changes:

  • Selects the SDK profile at import and the default login profile from RUNPOD_PROFILE, with blank values falling back to default.
  • Adds tests for profile selection, credential loading, and override precedence.
  • Documents the environment variable in getting-started and CLI guides.
File Description
tests/​test_profile.py Tests profile selection and API-key precedence.
tests/​test_cli/​test_management_commands.py Tests environment-based login profiles and explicit overrides.
runpod/​rp_cli/​main.py Uses the selected profile as the login default.
runpod/​__init__.py Initializes the SDK profile from RUNPOD_PROFILE.
docs/​getting_Started.md Documents profile selection before SDK import.
docs/​cli/​start_here.md Explains CLI profile selection and precedence.
docs/​cli/​references/​command_line_interface.md Adds environment-based profile selection to the reference.

Review effort: Balanced

Comment thread runpod/__init__.py Resolved
@deanq
deanq requested review from a team and marie-karpinska November 6, 2026 00:45
deanq and others added 2 commits November 5, 2026 17:59
A RUNPOD_PROFILE pointing at a profile with only S3 credentials made
`import runpod` raise KeyError: 'api_key' when RUNPOD_API_KEY was
unset, which also blocked `rp login --api-key`. Read the key with
.get so such a profile yields api_key = None.

@briandconnelly briandconnelly left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found.

No reportable defects were found in the reviewed scope. Tests were read, not run.

What changed

The pull request uses RUNPOD_PROFILE to select the SDK credential profile and the default profile for rp login, while preserving explicit profile and API-key overrides. It also tolerates stored profiles without an API key and adds documentation and tests.

👾 Reviewed by review-agent (GPT-6.1 Sol) on behalf of briandconnelly

Commit 1e5b8e5 · 0 inline comments

deanq added 3 commits November 7, 2026 10:25
- credentials live in ~/.runpod/config.toml, one table per profile,
  not ~/.runpod/credentials.toml
- setting runpod.profile after import does not change the key; the
  profile and key are read once at import, so document RUNPOD_PROFILE
  (set before import), rp login --profile, and RUNPOD_API_KEY
  precedence
- rename docs/getting_Started.md to docs/getting_started.md
The rename moves to its own change so file history follows it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants