Add a tool from an HTTP API

The agent gets a command that calls the API, and Spotlight keeps the API key, which the agent never sees. You need:

  • Terraform set up with the Spotlight provider, using a token that has the configure and secrets scopes. See Manage Spotlight with Terraform.
  • A key for the API.
  • On a self-hosted Spotlight with an outbound allow-list, the list includes the API's host. Spotlight calls the API from its own servers.

If the API publishes an OpenAPI spec or a GraphQL schema, see Generate tools from an API spec instead.

The example uses a placeholder API at api.acme.example that takes a comment as a JSON POST to /comments. Put your own API's host, path and body in its place.

Store the API key as a secret

Bind the secret to the API's host, in the header and with the prefix the API expects. Spotlight sends it to that host only, over HTTPS.

variable "acme_api_key" {
  type      = string
  sensitive = true
}

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

resource "spotlight_secret" "acme_api_key" {
  workspace_id = data.spotlight_workspace.acme.id
  name         = "ACME_API_KEY"
  bindings = [
    { host = "api.acme.example", location = "header", name = "authorization", prefix = "Bearer " },
  ]
  value_wo         = var.acme_api_key
  value_wo_version = 1
}

To rotate the key later, give the new value and raise value_wo_version. To keep the key out of Terraform, leave out value_wo and value_wo_version, and set the value in the web app or with spotlight secret set ACME_API_KEY. See Set the value outside Terraform.

If the API reads the key from the query

Some APIs, such as Google Maps, take the key as a query parameter. Bind the secret with location = "query" and the parameter's name:

resource "spotlight_secret" "maps_key" {
  workspace_id = data.spotlight_workspace.acme.id
  name         = "MAPS_KEY"
  bindings = [
    { host = "maps.googleapis.com", location = "query", name = "key" },
  ]
  value_wo         = var.maps_key
  value_wo_version = 1
}

Leave the key out of the request's url and name only the secret, as in auth = { secrets = ["secret.MAPS_KEY"] }. For how Spotlight sets the parameter and keeps the key out of what it records, see Bindings.

Define the action and the tool

Write the request as an action, and offer it to agents as a tool: action names the action, description tells the agent when to use it, and each input becomes a flag. In the request, read the inputs as inputs.<name> and name the secret in auth.secrets.

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

resource "spotlight_integration" "acme" {
  team_id = data.spotlight_team.core.id
  definition = {
    integration = "acme"
    actions = {
      comment = {
        request = {
          method = "POST"
          url    = "https://api.acme.example/comments"
          body = {
            issue = "$${{ inputs.issue }}"
            text  = "$${{ inputs.body }}"
          }
          auth = { secrets = ["secret.${spotlight_secret.acme_api_key.name}"] }
        }
      }
    }
    tools = {
      comment = {
        action      = "comment"
        description = "Comment on the issue."
        inputs = {
          issue = { type = "string", required = true }
          body  = { type = "string", required = true }
        }
      }
    }
  }
}

An input is text unless you say otherwise. For a number, give it type = "integer" or type = "number", and for a flag that is on or off, type = "boolean". For a list or an object, give its JSON Schema as schema in place of type; the agent then passes it as JSON:

labels = { schema = { type = "array", items = { type = "string" } } }

If the API names a field team_id or teamId, name the input the same way: an input name may contain letters, digits, _ and -.

Enable the tool at a station

Add the tool to the station's tools in the line. Name it through the integration's tools map, so renaming or removing the tool fails the plan here:

station {
  key       = "implementation"
  name      = "Implementation"
  harness   = "claude-code"
  tools     = [spotlight_integration.acme.tools["comment"]]
  passes_to = ["code-review"]
}

Outside Terraform, the name is <integration>.<tool>, as in acme.comment.

If the tool is for the tasks that the integration opens, set enabledOnMark to the mark kind that its events put on those tasks, as in enabledOnMark = "acme.issue". Then each run on a task with that mark has the tool, at every station. See Enabled on a mark.

Run terraform apply. The next run at that station has the tool. Its agent calls it with spotlight tools call:

spotlight tools call acme.comment --issue ACME-42 --body "Fixed in the linked pull request."

spotlight tools lists the tools enabled for a run, with their flags. spotlight tools describe acme.comment prints one with its inputs and an example call.

See what a tool answers with

After a call to the tool succeeds, Spotlight infers the shape of its answer: the field names and their types, never the values. In runs that start after that call, spotlight tools describe prints it under Answers with (inferred from earlier calls, may be incomplete):, so the agent knows which fields to read. Each later successful call adds to it. Updating or deleting the integration, and deleting the team, deletes what was inferred. See Inferred output.

If a person should agree before each call, see Require approval before a tool runs.

Call an API in your own network

If the API is reachable only from inside your network, let a host in that network send the request. You need:

On the host, add the API's host to the egress allow-list. Egress connects to a private address only for a host that the list names. The command replaces the list, so keep the entries it has:

spotlight host config set egress-allow=api.anthropic.com,api.acme.internal

Set from on the action, and optionally timeoutSeconds, 1 to 60, default 30:

    actions = {
      comment = {
        from           = "network"
        timeoutSeconds = 20
        request = {
          method = "POST"
          url    = "https://api.acme.internal/comments"
          body = {
            issue = "$${{ inputs.issue }}"
            text  = "$${{ inputs.body }}"
          }
          auth = { secrets = ["secret.${spotlight_secret.acme_api_key.name}"] }
        }
      }
    }

Run terraform apply, then call the tool from a run. The host logs recorded the response of a call with the status. If the call fails:

  • With no host of the workspace sent it within <n> seconds, run spotlight host status on the host to check that it is running and reports to the workspace.
  • With The host's allow-list doesn't allow <host>., add the host to egress-allow.
  • With Egress couldn't redeem the call's secrets, check the host's log for the reason.
  • With Egress couldn't inject secret <NAME>, check that egress-allow allows the secret's bound host.

For every rule and message, see Sent from the network.

On this page