Custom API

Make authenticated HTTP requests to any external API with CustomApiTools.

CustomApiTools enable an Agent to make HTTP requests to any external API with customizable authentication and parameters.

Prerequisites

The following example requires the requests and openai libraries.

uv pip install agno requests openai

Example

The following agent will use CustomApiTools to make API calls to the Dog CEO API.

cookbook/91_tools/custom_api_tools.py
from agno.agent import Agent
from agno.tools.api import CustomApiTools

agent = Agent(
    tools=[CustomApiTools(base_url="https://dog.ceo/api", enable_make_request=True)],
    markdown=True,
)

agent.print_response(
    'Make api calls to the following two different endpoints- /breeds/image/random and /breeds/list/all to get a random dog image and list of dog breeds respectively. Make sure that the method is "GET" for both the api calls.'
)

Toolkit Params

ParameterTypeDefaultDescription
base_urlOptional[str]NoneBase URL for API calls
usernameOptional[str]NoneUsername for basic authentication
passwordOptional[str]NonePassword for basic authentication
api_keyOptional[str]NoneAPI key for bearer token authentication
headersOptional[Dict[str, str]]NoneDefault headers to include in requests
verify_sslboolTrueWhether to verify SSL certificates
timeoutint30Request timeout in seconds
enable_make_requestboolTrueEnables functionality to make HTTP requests
allboolFalseEnables all functionality when set to True

Toolkit Functions

FunctionDescription
make_requestMakes an HTTP request to the API. Takes method (GET, POST, etc.), endpoint, and optional params, data, headers, and json_data parameters.

Bearer authentication

The constructor's api_key adds an Authorization bearer header only when base_url is set. When calling a full endpoint URL without a base URL, pass the header explicitly:

from os import environ
from agno.tools.api import CustomApiTools

api = CustomApiTools(
    headers={"Authorization": f"Bearer {environ['SERVICE_API_KEY']}"},
)

Set SERVICE_API_KEY to your service's token before using this configuration. Username/password authentication is configured separately.

Developer Resources