How to Use API Function Calling Using OpenAI Assistant
Step-by-step guide to support API function calling in your OpenAI Assistant
You can make third-party APIs available to your Assistant by providing details about the endpoints, parameters, and a description about how the model should use it. It is similar to Custom Actions in OpenAI GPTs, but it functions within the OpenAI Assistant.
Understanding How Function Calling Works
Check OpenAI Assistant Function Calling to learn how it works.
Adding API Function Calling to Assistant
Runbear supports API calls in OpenAI Assistant. This can
be achieved by simply adding the __api__
property under
parameters.properties
in the Function JSON.
__api__
Property
**api** object consists of the following properties:
- type: This should be
object
. - value: This should be an object with the following properties:
- url: URL of the API endpoint
- method (optional): HTTP method to use (GET, POST, PUT, DELETE, etc.)
- headers (optional): HTTP headers to send
URL String Interpolation
You can interpolate parameters into the URL. For example, to interpolate a
resource
parameter into the URL, use the {resource}
string within the URL.
Example
This example shows how to add a REST API to your Assistant Function. The function retrieves information of people in Star Wars.
{
"name": "search_starwars",
"parameters": {
"type": "object",
"properties": {
"search": {
"type": "string",
"description": "Search keyword"
},
"resource": {
"type": "string",
"description": "Type of searching resource. The value should be one of 'people', 'planets' or 'starships'."
},
"__api__": {
"type": "object",
"value": {
"url": "https://swapi.dev/api/{resource}/",
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
}
}
},
"required": ["search", "resource"]
},
"description": "Search about the keyword from Starwars"
}
This enables OpenAI Assistant to call the API endpoint with extracted parameters.