
Create a secret
Secrets are strings stored as key-value pairs. To create a secret, go to the Vault tab in the Agent Builder UI and click +Add a pair. The example below creates a secret with the nameWRITER_API_KEY
. When you type the value, it’s masked in the UI.
Click Save to store the secret.

Where secrets are available
Within Python code, Vault is a runtime-only feature that’s injected into specific execution contexts, not into the main module scope. It isn’t a global variable and is only available in the execution context of the blueprint. This design provides security benefits:- Secrets are only loaded when needed
- Access is limited to proper execution contexts
- No global exposure of sensitive data
- Event handlers and blueprint code blocks: Secrets are injected into event handlers and blueprint code blocks when they run. This includes:
- Button click handlers
- Form submission handlers
- Page load handlers
- Custom event handlers
- Blueprint execution environment: Secrets are injected into the blueprint execution environment when the blueprint runs and can be referenced from any blueprint block.
Access your Writer API key
Each Agent Builder agent in the online editor has a Writer API key set as an environment variable calledWRITER_API_KEY
. If you want to use this API key with other Writer API calls, you can access it with os.getenv('WRITER_API_KEY')
. This allows you to access the API key outside of event handlers and blueprint code blocks, and means you don’t need to set a new secret in Vault for your API key.
Examples
Secrets in Python code blocks
You can reference secrets in Python code blocks within blueprints using thevault
object. vault
is a dictionary that contains all the secrets in your blueprint.
For example, to access a secret called ACME_API_KEY
and use it in an HTTP request, you would use the following code: