OpenAPIServiceToFunctions
Convert OpenAPI service definitions into function-calling format for LLMs. Use this component to expose REST API operations as tools that chat generators can invoke.
Key Features
- Converts OpenAPI 3.0+ specifications into OpenAI-compatible function definitions.
- Accepts OpenAPI specs as file paths or
ByteStreamobjects in JSON or YAML format. - Resolves JSON references in the specification.
- Outputs both function definitions and parsed OpenAPI specs for downstream connectors.
Configuration
Add Workspace-Level Integration
- Click your profile icon and choose Settings.
- Go to Workspace>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in the current workspace.
Add Organization-Level Integration
- Click your profile icon and choose Settings.
- Go to Organization>Integrations.
- Find the provider you want to connect and click Connect next to them.
- Enter the API key and any other required details.
- Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
- Drag the
OpenAPIServiceToFunctionscomponent onto the canvas from the Component Library. - Connect a component that provides OpenAPI specification sources (file paths or
ByteStreamobjects) to thesourcesinput. - Connect the
functionsoutput to a chat generator that supports tool calling. - Connect the
openapi_specsoutput toOpenAPIServiceConnectorfor executing tool calls.
Each operation in the spec must have a unique operationId, a description, and a schema for its parameters or request body.
Connections
OpenAPIServiceToFunctions receives a list of OpenAPI specification sources. It outputs functions (tool definitions for the LLM) and openapi_specs (parsed specs with resolved references for the service connector).
Source Code
To check this component's source code, open openapi_functions.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
OpenAPIServiceToFunctions:
type: haystack_integrations.components.converters.openapi.openapi_functions.OpenAPIServiceToFunctions
init_parameters: {}
Use it with OpenAPIServiceConnector by adapting the list of specs to a single dict with OutputAdapter:
# haystack-pipeline
components:
spec_converter:
type: haystack_integrations.components.converters.openapi.openapi_functions.OpenAPIServiceToFunctions
init_parameters: {}
openapi_spec_adapter:
type: haystack.components.converters.output_adapter.OutputAdapter
init_parameters:
template: "{{ specs[0] }}"
output_type: Dict[str, Any]
unsafe: true
service_connector:
type: haystack_integrations.components.connectors.openapi.openapi_service.OpenAPIServiceConnector
init_parameters: {}
connections:
- sender: spec_converter.openapi_specs
receiver: openapi_spec_adapter.specs
- sender: openapi_spec_adapter.output
receiver: service_connector.service_openapi_spec
inputs:
sources:
- spec_converter.sources
messages:
- service_connector.messages
outputs:
functions: spec_converter.functions
service_response: service_connector.service_response
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
sources | List[str | Path | ByteStream] | File paths or ByteStream objects of OpenAPI definitions in JSON or YAML format. |
Outputs
| Parameter | Type | Description |
|---|---|---|
functions | List[Dict[str, Any]] | Function definitions in OpenAI function-calling format. |
openapi_specs | List[Dict[str, Any]] | Parsed OpenAPI specs with resolved references. |
Init Parameters
This component has no init parameters.
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
sources | List[str | Path | ByteStream] | OpenAPI specification sources to convert. |
Related Information
Was this page helpful?