Give agents a secret for an API

This page is for requests that the agent sends itself, for example with curl to a staging server. For a key that an MCP server reads from its environment, see Give an MCP server a secret.

The example uses a placeholder API, staging.acme.example, that reads a token from the authorization header with the prefix Bearer . Put your own host, header and prefix in their place. You need:

Keep the token as a secret bound to the API's host

data "spotlight_workspace" "acme" {
  slug = "acme"
}

resource "spotlight_secret" "staging_viewer" {
  workspace_id = data.spotlight_workspace.acme.id
  name         = "STAGING_VIEWER"
  bindings = [
    { host = "staging.acme.example", location = "header", name = "authorization", prefix = "Bearer " },
  ]
}

This secret has no value in Terraform. After terraform apply, set it in the web app under Settings, then Secrets, or with spotlight secret set STAGING_VIEWER. To set it from Terraform instead, add value_wo and value_wo_version. See Value.

Name the secret in a harness profile

data "spotlight_team" "core" {
  workspace_id = data.spotlight_workspace.acme.id
  key          = "core"
}

resource "spotlight_harness_profile" "staging" {
  team_id = data.spotlight_team.core.id
  key     = "staging"
  secrets = [spotlight_secret.staging_viewer.name]
}

The secret must exist before the profile names it, and it cannot be deleted while the profile names it. While the secret has no value, the profile's answer has the warning names secret STAGING_VIEWER, which has no value. Runs with this profile do not start until a person sets it

Run a station with the profile

Set the station's profile to the profile's key:

station {
  key       = "verify"
  name      = "Verify"
  harness   = "claude-code"
  profile   = spotlight_harness_profile.staging.key
  passes_to = ["code-review"]
}

Run terraform apply. The briefing of the next run at that station has a Secrets section:

- `STAGING_VIEWER` to staging.acme.example: send `Bearer spotlight-egress:STAGING_VIEWER` in the `authorization` header

The agent sends the stand-in, as in curl -H "authorization: Bearer spotlight-egress:STAGING_VIEWER" https://staging.acme.example/health, and egress puts the real token in its place in the outgoing request. The agent never sees the token. A request to staging.acme.example without the stand-in goes out without the token.

A run at the station fails with secret_awaiting_value: Secret STAGING_VIEWER has no value. Station: Verify while the secret has no value. Setting the value does not start that run again. Reply to its inbox item to start a new run.

If the host, or the shared egress of a push pool, sets SPOTLIGHT_EGRESS_ALLOW, the list must allow the API's host, or egress blocks the agent's requests to it.

On this page