-
Notifications
You must be signed in to change notification settings - Fork 30
docs: add Settings and Secrets API guide #490
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
Draft
malhotra5
wants to merge
5
commits into
main
Choose a base branch
from
feat/encrypted-secrets-in-transit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9fcff3b
docs: add Settings and Secrets API guide
openhands-agent 614cfae
chore: run auto sync script to update code blocks from agent-sdk
openhands-agent f831b62
docs: update settings/secrets API guide for real agent session
openhands-agent 040fd3d
docs: update for REST API conversation start with secrets_encrypted
openhands-agent d637a6d
docs: use encrypted_llm directly from settings response
openhands-agent 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| --- | ||
| title: Settings and Secrets API | ||
| description: Manage agent settings and custom secrets through the agent server REST API. | ||
| --- | ||
|
|
||
| import RunExampleCode from "/sdk/shared-snippets/how-to-run-example.mdx"; | ||
|
|
||
| > A ready-to-run example is available [here](#ready-to-run-example)! | ||
|
|
||
| The Settings and Secrets API provides REST endpoints for managing agent configuration and custom secrets through a local agent server. This is useful for: | ||
|
|
||
| - Persisting agent settings across sessions | ||
| - Managing custom secrets (API keys, tokens, credentials) | ||
| - Integrating with frontend applications that need settings management | ||
|
|
||
| ## Key Concepts | ||
|
|
||
| ### Settings Endpoints | ||
|
|
||
| The agent server exposes settings management via REST: | ||
|
|
||
| - **GET /api/settings** - Retrieve current settings | ||
| - **PATCH /api/settings** - Update settings with a partial diff | ||
|
|
||
| ```python icon="python" | ||
| # Get current settings | ||
| response = client.get("/api/settings") | ||
| settings = response.json() | ||
|
|
||
| # Update LLM model | ||
| response = client.patch( | ||
| "/api/settings", | ||
| json={"agent_settings_diff": {"llm": {"model": "gpt-4o-mini"}}}, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Secrets CRUD Operations | ||
|
|
||
| Custom secrets can be created, listed, retrieved, and deleted: | ||
|
|
||
| ```python icon="python" | ||
| # Create a secret | ||
| client.put( | ||
| "/api/settings/secrets", | ||
| json={ | ||
| "name": "MY_API_KEY", | ||
| "value": "sk-example-key-12345", | ||
| "description": "Example API key", | ||
| }, | ||
| ) | ||
|
|
||
| # List secrets (values not exposed) | ||
| secrets = client.get("/api/settings/secrets").json()["secrets"] | ||
|
|
||
| # Get secret value | ||
| value = client.get("/api/settings/secrets/MY_API_KEY").text | ||
|
|
||
| # Delete secret | ||
| client.delete("/api/settings/secrets/MY_API_KEY") | ||
| ``` | ||
|
|
||
| ### Secret Name Validation | ||
|
|
||
| Secret names must follow environment variable naming conventions: | ||
|
|
||
| - Start with a letter (a-z, A-Z) | ||
| - Contain only letters, numbers, and underscores | ||
| - Be 1-64 characters long | ||
|
|
||
| Invalid names are rejected with a 422 response: | ||
|
|
||
| ```python icon="python" | ||
| # Invalid: starts with number | ||
| response = client.put( | ||
| "/api/settings/secrets", | ||
| json={"name": "123_invalid", "value": "test"}, | ||
| ) | ||
| assert response.status_code == 422 | ||
|
|
||
| # Invalid: contains hyphen | ||
| response = client.put( | ||
| "/api/settings/secrets", | ||
| json={"name": "invalid-name", "value": "test"}, | ||
| ) | ||
| assert response.status_code == 422 | ||
| ``` | ||
|
|
||
| ### Secret Redaction | ||
|
|
||
| When retrieving settings, secrets are redacted by default to prevent accidental exposure: | ||
|
|
||
| ```python icon="python" | ||
| # Update LLM API key | ||
| client.patch( | ||
| "/api/settings", | ||
| json={"agent_settings_diff": {"llm": {"api_key": "sk-live-test-key"}}}, | ||
| ) | ||
|
|
||
| # Get settings - key is redacted | ||
| response = client.get("/api/settings") | ||
| assert response.json()["agent_settings"]["llm"]["api_key"] == "**********" | ||
| assert response.json()["llm_api_key_is_set"] is True | ||
| ``` | ||
|
|
||
| ## Ready-to-Run Example | ||
|
|
||
| This example starts a local agent server and exercises the full settings and secrets API: | ||
|
|
||
| ```python icon="python" expandable examples/02_remote_agent_server/12_settings_and_secrets_api.py | ||
| <code will be auto-synced> | ||
| ``` | ||
|
|
||
| <RunExampleCode path_to_script="examples/02_remote_agent_server/12_settings_and_secrets_api.py"/> | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - **[Local Agent Server](/sdk/guides/agent-server/local-server)** - Run agents through a local HTTP server | ||
| - **[Docker Sandboxed Server](/sdk/guides/agent-server/docker-sandbox)** - Run server in Docker for isolation | ||
| - **[Agent Server Overview](/sdk/guides/agent-server/overview)** - Architecture and implementation details | ||
Oops, something went wrong.
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.