Custom API
CustomApiTools enable an Agent to make HTTP requests to any external API with customizable authentication and parameters.
Prerequisites
The following example requires the requests library.
1uv pip install requestsExample
The following agent will use CustomApiTools to make API calls to the Dog CEO API.
1from kern.agent import Agent2from kern.tools.api import CustomApiTools34agent = Agent(5 tools=[CustomApiTools(base_url="https://dog.ceo/api")],6 markdown=True,7)89agent.print_response(10 '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. Use GET method for both calls.'11)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
base_url | str | None | Base URL for API calls |
username | str | None | Username for basic authentication |
password | str | None | Password for basic authentication |
api_key | str | None | API key for bearer token authentication |
headers | Dict[str, str] | None | Default headers to include in requests |
verify_ssl | bool | True | Whether to verify SSL certificates |
timeout | int | 30 | Request timeout in seconds |
enable_make_request | bool | True | Enables functionality to make HTTP requests |
all | bool | False | Enables all functionality when set to True |
Toolkit Functions
| Function | Description |
|---|---|
make_request | Makes an HTTP request to the API. Takes method (GET, POST, etc.), endpoint, and optional params, data, headers, and json_data parameters. |
Developer Resources
- View Tools