Skip to main content

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

If the AI calls with {"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

Use the Marketplace to install pre-configured tools that handle authentication setup for popular services.

Examples

Product Search (GET)

Order Lookup (GET)

Create Support Ticket (POST)

Update Record (PUT)

Response Handling

Successful Responses

The API response is:
  1. Passed to the AI for interpretation
  2. Formatted according to displayConfig (if specified)
  3. 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:
See Display Configuration for all options.

Testing HTTP Tools

Mock Mode

Before connecting to live APIs, test with mock mode:

Live Testing

  1. Create the tool with your API configuration
  2. Open the chat playground
  3. Ask a question that should trigger the tool
  4. 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