OpenAPI Chain
The OpenAPI Chain node is designed to automatically select and call APIs based on an OpenAPI specification. It interprets user queries, selects the appropriate API endpoint, and executes the call, providing a natural language interface to complex API systems.
Node Details
- Name:
openApiChain
- Type:
OpenAPIChain
- Category: [[API Chain|Chains]]
- Version: 2.0
- Icon: openapi.svg
- Description: Chain that automatically select and call APIs based only on an OpenAPI spec
Parameters
-
Chat Model (Required)
- Type: BaseChatModel
- Description: The chat model used for interpreting queries and generating responses.
-
YAML Link (Optional)
- Type: string
- Description: URL link to the OpenAPI specification in YAML format.
- Placeholder: https://api.speak.com/openapi.yaml
- Note: If YAML link is provided, uploaded YAML File will be ignored.
-
YAML File (Optional)
- Type: file
- File Type: .yaml
- Description: Uploaded OpenAPI specification file in YAML format.
- Note: Ignored if YAML link is provided.
-
Headers (Optional)
- Type: json
- Description: Additional headers to be included in API requests.
- Additional Params: true
-
Input Moderation (Optional)
- Type: Moderation[]
- Description: Moderation tools to detect and prevent harmful input.
- Additional Params: true
Input
- A string containing the user’s query or instruction related to the API.
Output
- Either a string or an object containing:
- The response from the API call
- Any additional information or context provided by the chain
How It Works
- The chain loads the OpenAPI specification from either the provided YAML link or uploaded file.
- It receives a user query or instruction.
- The chat model interprets the query to determine which API endpoint and method to use.
- The chain constructs the appropriate API request, including any necessary parameters or headers.
- It executes the API call and receives the response.
- The chat model then interprets the API response and generates a human-readable answer to the original query.
- The final response is returned, potentially including both the raw API data and the interpreted answer.
Use Cases
- Creating natural language interfaces for complex API systems
- Automating API interactions in chatbots or virtual assistants
- Simplifying API usage for non-technical users
- Rapid prototyping and testing of API-based applications
- Integrating multiple API endpoints to answer complex queries
Special Features
- Automatic API Selection: Chooses the appropriate API endpoint based on natural language input.
- OpenAPI Spec Compatibility: Works with standard OpenAPI (formerly Swagger) specifications.
- Flexible Input: Accepts OpenAPI specs via URL or file upload.
- Header Customization: Allows addition of custom headers for authentication or other purposes.
- Input Moderation: Optional moderation to prevent processing of potentially harmful queries.
- Streaming Support: Can provide streaming responses for real-time interaction.
Notes
- The effectiveness of the chain depends on the quality and completeness of the OpenAPI specification.
- It’s important to ensure that the provided chat model is capable of understanding and working with API concepts.
- The chain supports both YAML and JSON formats for OpenAPI specifications, but YAML is preferred.
- When using file upload, ensure that the YAML file is properly formatted and complete.
- The chain can handle complex API structures, including nested objects and arrays in requests and responses.
- For optimal performance, it’s recommended to use a chat model that has been fine-tuned or trained on API-related tasks.
The OpenAPI Chain node provides a powerful solution for creating intelligent, natural language interfaces to API systems defined by OpenAPI specifications. By leveraging advanced language models and standardized API descriptions, it enables developers to quickly build sophisticated applications that can interact with complex APIs based on simple user queries. This node is particularly valuable in scenarios where you want to provide easy access to API functionality without requiring users to understand the technical details of API operation.