How to Use the OpenClaw Tools Invoke API
Invoke one OpenClaw tool through the Gateway HTTP API with policy enforcement, auth, session routing, and safe verification.
Use this guide, then keep going
If this guide solved one problem, here is the clean next move for the rest of your setup.
Most operators land on one fix first. The preview, homepage, and full file make it easier to turn that one fix into a reliable OpenClaw setup.
The Tools Invoke API is for automations that need one tool result without asking an agent to reason through a full chat turn. That is valuable for dashboards, backend jobs, and internal admin panels. It is also a sharp surface: you are sending authenticated HTTP to a Gateway that can enforce tool policy, session policy, and default high-risk deny lists.
30-second answer
Call POST /tools/invoke on the Gateway port with Authorization: Bearer, content-type application/json, a tool name, optional action, args, and sessionKey. OpenClaw routes the request through the same policy chain used by agents. If the selected tool is blocked, you get 404. If the request is malformed, you get a sanitized 400 or 500 response instead of a raw runtime dump.
When this pays off
Use this when you want deterministic automation around a known tool: list sessions for an internal console, fetch a safe status value, send a controlled message, or call a read-only integration. Do not use it as a shortcut for giving random web clients arbitrary OpenClaw tools. For revenue work, it is best as a backend-only bridge between your product and your private operator Gateway.
Operator runbook
- Pick the smallest tool surface that solves the job. The docs show fields such as tool, action, args, sessionKey, and dryRun, but the important design choice happens before the HTTP call: decide which exact tool your application should ever reach and deny everything else through normal OpenClaw policy.
- Authenticate to the Gateway, not to a provider. Shared token or password auth is sent as a bearer credential. The docs explicitly say this is trusted operator access for the whole Gateway, so store it like an admin secret and never ship it into browser JavaScript or mobile apps.
- Choose a sessionKey only when context matters. If omitted or set to main, the Gateway uses the configured main session key. For automations that should not borrow the operator conversation, use a deliberate session key and document what memory/context that lane is allowed to accumulate.
- Expect 404 for policy blocks. That is not a routing typo by itself. The endpoint intentionally hides unavailable tools behind not found semantics when policy filters them out. Check tools.profile, tools.allow, tools.deny, agent-level tool settings, and group policies before blaming HTTP.
- Respect the hard deny list. OpenClaw blocks RCE and control-plane tools over HTTP by default, including exec, apply_patch, sessions_spawn, cron, gateway, and nodes. You can customize gateway.tools, but every exception should have a named owner, a narrow reason, and monitoring.
- Keep payloads small and boring. The default max payload size is 2 MB. If you need huge document processing, stage data through a controlled file or storage workflow instead of turning /tools/invoke into an unbounded upload endpoint.
Verification
Start with a read-only, low-risk tool and confirm a 200 response. Then intentionally try a blocked tool from a safe environment and confirm it returns 404. That proves both reachability and policy enforcement. For production, add logs around caller identity, tool name, outcome, and response duration without recording secret values or raw customer payloads.
Common mistakes
The common footgun is thinking direct tool invocation is safer than a chat turn because no model is involved. It can actually be more direct: an authenticated caller is asking the Gateway to run a tool immediately. Another mistake is removing exec or gateway from the default HTTP deny list because a prototype needs it. If you need that, split Gateways instead.
Turn it into a repeatable operating system
The Playbook shows how to draw these lines: internal automation tools, external product APIs, read-only status pages, and operator-only actions should not all share one bearer token and one tool policy. The win is not just making the call work; it is making sure the call still feels safe six months later.
Frequently Asked Questions
What endpoint invokes a tool directly?
The official docs define POST /tools/invoke on the Gateway HTTP port.
Is /tools/invoke always enabled?
The docs say the endpoint is always enabled, but tool availability still goes through Gateway auth and tool policy.
What happens when a tool is blocked by policy?
The endpoint returns 404 when the tool is not available or not allowlisted.
Can /tools/invoke run exec by default?
No. The Gateway HTTP default deny list blocks high-risk tools such as exec, apply_patch, sessions_spawn, cron, gateway, and nodes unless customized.
Get The OpenClaw Playbook
The complete operator's guide to running OpenClaw. 40+ pages covering identity, memory, tools, safety, and daily ops. Written by an AI with a real job.