Python library to convert OpenAPI endpoints into callable tools for LLM AI agents.
Project description
OpenAPI AI
This is a Python library that helps AI agents to connect to, talk to, and consume existing web REST API endpoints built with OpenAPI standard. It does so by generating tools at runtime that can be called by LLM-based agents built with OpenAI Agents SDK or Google ADK.
Usage
First, you need to install the package:
pip install openapi-ai
In this example, we will be using this server that is running at localhost.
import os
import asyncio
from dotenv import load_dotenv
from agents import Agent, Runner
from openapi_ai import OpenAPITools
load_dotenv()
async def main():
tools = OpenAPITools("http://localhost:8000/openapi.json", remove_prefix="/api/v1")
agent = Agent(
name="Haiku trading agent",
instructions="You are a trading assistant. Always answer in haiku form.",
model="gpt-4o",
tools=tools.get_openai_tools(),
)
result = await Runner.run(agent, "What is my current account info?")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
"""
Example output:
Real account holds much,
Balance strong in dollars vast,
Equity shines bright.
Leverage set high,
Profit flows, free margin wide,
In currency's might.
"""
Use Cases
1. Enterprise Automation & Internal Tools Integration
Many companies have internal web tools for things like HR, project tracking, or customer information. Often, these tools have APIs described using the OpenAPI standard. OpenAPI AI library can read these descriptions and automatically create Python functions. This allows an AI agent (built with OpenAI or Google agent SDKs) to use these functions to interact with the company's tools, potentially letting users ask for information or perform simple tasks in one place.
2. Giving AI Agents Access to Live Information
AI models know a lot, but they don't always have the latest information like current weather, live stock prices, or if a product is in stock right now. If a service provides this live data through an API with an OpenAPI description, OpenAPI AI library can generate tools for it. An AI agent can then use these tools to fetch the real-time data when needed, helping it give more current and specific answers.
3. Helping AI Agents Interact with External Web Services
Sometimes you might want an AI agent to do something on another website or platform, like adding an issue to GitHub or posting a basic message. If these external services offer an API documented with OpenAPI, OpenAPI AI library can create the functions for those actions. An agent using these functions (with the right permissions and authentication) could then perform tasks on those platforms based on user requests.
4. Speeding Up AI Agent Development with API Integration
Certain tasks involve multiple steps using different APIs, for example, checking flight availability and then looking for hotels, or getting data from a CRM and sending it to a marketing tool. If the APIs for these steps are described using OpenAPI, OpenAPI AI library can generate functions for each one. An AI agent could then potentially manage the sequence of calling these functions to complete the overall task.
5. Rapid Prototyping and Development
When building an AI agent that needs to use web APIs, developers typically write code to make the API calls. OpenAPI AI library helps automate part of this. By reading an API's OpenAPI specification file, it generates the basic Python functions an agent (using OpenAI or Google SDKs) needs to call that API. This can save development time, letting builders focus more on the agent's core logic rather than writing repetitive API connection code.
6. Enabling AI for Legacy Systems
Sometimes, older company systems don't have modern APIs that AI agents can easily use. A common approach is to build a simpler, modern API "wrapper" around the old system and describe this wrapper using OpenAPI. OpenAPI AI library can then read the wrapper's OpenAPI description and generate functions for it, providing a way for an AI agent to communicate with the underlying legacy system indirectly.
Roadmap
Project Checklist
- ✅ Generate python functions from OpenAPI server endpoints
- ✅ Integrate Pydantic
- ✅ Generate function tools for OpenAI Agent SDK
- Generate function tools for Google ADK
- Support for endpoints with multiple path parameters
- Authentication
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openapi_ai-0.4.0.tar.gz.
File metadata
- Download URL: openapi_ai-0.4.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feb7f3e8e04330bd7df4c5cc4c51423dff13218884ec696b7b4ffa8bcddb3c69
|
|
| MD5 |
5770ff2acf49d9100a3c36424b63c130
|
|
| BLAKE2b-256 |
e73bc2eecb789c2421baacc356cd1079f91ab234b5f15b0d0a3a2176580cdfd0
|
File details
Details for the file openapi_ai-0.4.0-py3-none-any.whl.
File metadata
- Download URL: openapi_ai-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2559b488d5f8e4fe035eccb9238f5a7657f8052f1e7508e6139b2aade51f8ae5
|
|
| MD5 |
6b79d436bc92873e922285d17a65275b
|
|
| BLAKE2b-256 |
e2b5fcfa4666f53ac05eaae04bfb6bd5b24ae2a8ca9dcc417a07a6f52c841b7c
|