How tool calls work
When the model emits a tool call during a stream, HASP intercepts it at the gateway before any execution occurs:- Pre-action authorization — The gateway checks whether the caller (user, API key, or agent credential) holds the necessary scope to invoke this tool. Unauthorized calls return
403 TOOL_NOT_IN_SCOPEand are never executed. - PHI scan — Tool inputs are scanned for PHI. By default, PHI is redacted from inputs before execution. If your org’s
phi_retrieval_behaviorisblock, calls with PHI in their inputs return403 RETRIEVAL_PHI_BLOCKEDinstead. - Execution — The tool runs. Results are injected back into the model’s context.
- Credit deduction — On success, AI Credits are debited: a flat per-call surcharge (tool-specific) plus the normal input-token cost for the injected result content. No charge is applied for failed tool calls.
- Audit log — A tool invocation event is written to the integrity-chain audit log, recording the call, the PHI scan result, the outcome, and the credit debit.
- Continuation — The model receives the result and continues the stream.
PHI guarantee
Tool inputs are scanned for PHI before any tool executes. External providers invoked by HASP tools (for example, web retrieval providers Tavily and Serper) never receive PHI under any circumstance. This is a hard architectural invariant, not a configuration option.Billing
Tool calls consume AI Credits in two ways:- Flat per-call surcharge — debited on provider success, tool-specific (see each tool’s page for the amount). No charge for failed calls.
- Injected-token cost — tool results injected into context count as input tokens at your normal per-token rate.
Agent scope grants
Agents must have an explicit scope grant to call a tool. A user or API key call always has access to built-in tools (subject to org-level feature availability). Agent credentials require ahasp.tool.invoke scope grant naming the specific tool.
See Scope Grants for how to authorize tool use in agent credentials.
Built-in tools
The following tools are available to all orgs with retrieval enabled:| Tool | Description | Credit surcharge |
|---|---|---|
web.search | Governed web search via HASP’s retrieval layer | 5 AI Credits / call |
web.fetch | Fetch readable text content from a specific URL | 2 AI Credits / call |