Custom API

Call arbitrary REST endpoints with CustomApiTools, hitting the dog.ceo API for a random dog image and the full breed list.

Integrate custom APIs with Agno agents using CustomApiTools.

Prerequisites

CustomApiTools accepts a base URL, basic authentication credentials, an API key, headers, SSL verification settings, and a request timeout.

from agno.agent import Agent
from agno.tools.api import CustomApiTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# Example 1: Enable specific API functions
agent = Agent(
    tools=[CustomApiTools(base_url="https://dog.ceo/api", enable_make_request=True)],
    markdown=True,
)

# Example 2: Enable all API functions
agent_all = Agent(
    tools=[CustomApiTools(base_url="https://dog.ceo/api", all=True)],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    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.'
    )

This example's API responses include an image URL; it does not download or attach image bytes. When adapting authentication, api_key adds a Bearer header only when base_url is set. For a full endpoint URL without a base URL, pass the required authorization header explicitly.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai requests

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as custom_api_tools.py, then run:

python custom_api_tools.py

Full source: cookbook/91_tools/custom_api_tools.py