Overview
HTTP tools allow your agent to:- Fetch data from external APIs
- Send data to webhooks
- Integrate with any REST API
- Display results with rich formatting
Configuration
Basic HTTP Tool
HTTP Configuration Options
Parameter Substitution
Use${paramName} to insert input parameters into URLs, headers, and bodies:
URL Parameters
{"productId": "123", "include": "reviews"}, the URL becomes:
Header Parameters
Request Body (POST/PUT)
For POST and PUT requests, the input schema parameters are sent as the JSON body:User Context Variables
In addition to AI-generated parameters (${param}), you can access user identity data using {{context}} syntax. This is useful for passing authentication tokens or user information to your APIs.
Available Variables
Setting Up User Identity
First, identify your user in your website’s JavaScript:Using Identity in Headers
Pass the user’s auth token to your API:Using Identity in URLs
The
{{context}} syntax is for user identity data (set via identify()), while ${param} is for AI-generated input values. You can use both in the same tool configuration.Security Considerations
- User identity is passed from the client-side widget, so treat it as untrusted input
- Your backend API should validate any auth tokens (JWT signature verification, etc.)
- Don’t rely solely on
{{userId}}for authorization - verify it against your session/token - The identity data is not stored by Ansa - it’s passed through to your APIs at runtime
Authentication
API Key in Header
API Key in URL
Basic Auth
Examples
Product Search (GET)
Order Lookup (GET)
Create Support Ticket (POST)
Update Record (PUT)
Response Handling
Successful Responses
The API response is:- Passed to the AI for interpretation
- Formatted according to
displayConfig(if specified) - Included in the agent’s response
Error Handling
If the API returns an error:- 4xx errors: Agent acknowledges the issue
- 5xx errors: Agent apologizes for technical difficulties
- Timeout: Agent suggests trying again
Display Configuration
Pair HTTP tools with display config for rich responses:Testing HTTP Tools
Mock Mode
Before connecting to live APIs, test with mock mode:Live Testing
- Create the tool with your API configuration
- Open the chat playground
- Ask a question that should trigger the tool
- Check the response and refine as needed
Best Practices
API Design
- Keep responses concise — Large responses slow down processing
- Return only needed fields — Use API filtering when available
- Handle pagination — Consider limits for list endpoints
Security
- Never expose secrets in URLs — Use headers for auth tokens
- Use HTTPS — All external APIs should use HTTPS
- Rotate keys — Update API keys regularly
Reliability
- Handle errors gracefully — Write descriptions that help AI explain failures
- Set timeouts — APIs should respond within 30 seconds
- Monitor usage — Track API calls to stay within limits
See Also
- Display Configuration — Rich response formatting
- Tools Overview — Tool types and AI integration
- Marketplace — Pre-built tool templates
- Webhooks — Receiving data from Ansa