Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

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 ByteStream objects 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

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. Drag the OpenAPIServiceToFunctions component onto the canvas from the Component Library.
  2. Connect a component that provides OpenAPI specification sources (file paths or ByteStream objects) to the sources input.
  3. Connect the functions output to a chat generator that supports tool calling.
  4. Connect the openapi_specs output to OpenAPIServiceConnector for 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

ParameterTypeDescription
sourcesList[str | Path | ByteStream]File paths or ByteStream objects of OpenAPI definitions in JSON or YAML format.

Outputs

ParameterTypeDescription
functionsList[Dict[str, Any]]Function definitions in OpenAI function-calling format.
openapi_specsList[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.

ParameterTypeDefaultDescription
sourcesList[str | Path | ByteStream]OpenAPI specification sources to convert.