OpenAI Response API
OpenAI's Responses is newly introduced API designed to help developers create advanced AI agents and workflows capable of performing tasks cloud-based tasks like web searches, file retrievals, and computer operations on behalf of users. This API streamlines the integration of OpenAI models with built-in tools, eliminating the need for multiple APIs or external services.
Key Features of the Responses API:
Built-in Tools: The API offers tools such as web search, file search, and computer use, enabling agents to access real-time information, retrieve specific documents, and perform tasks on a user's device. OpenAI Developer Community
Simplified Development: By combining the simplicity of Chat Completions with enhanced tool usage and state management, the Responses API facilitates the creation of more dynamic and capable AI experiences.
API Tour
Here is an example calling the Responses API to ask a simple question. This example uses file search (aka RAG) to augment the pre-trained knowledge of the LLM.
#include "ioto.h"
void example(void)
{
cchar *vectorId = "PUT_YOUR_VECTOR_ID_HERE";
char buf[1024];
/*
SDEF is used to catentate literal strings into a single string.
SFMT is used to format strings with variables.
jsonParse converts the string into a json object.
*/
Json *request = jsonParse(SFMT(buf, SDEF({
model: 'gpt-4o-mini',
input: 'What is the capital of the moon?',
tools: [{
type: 'file_search',
vector_store_ids: ['%s'],
}],
}), vectorId), 0);
Json *response = openaiResponse(request);
// Extract the LLM response text from the json payload
text = jsonGet(response, "output_text", 0);
printf("Response: %s\n", text);
jsonFree(request);
jsonFree(response);
}
The openaiResponse
API takes a JSON object which represents the Response parameters. The SDEF
macro is a convenience to make it easier to define JSON objects in C code. The SFMT macro expands printf
style expressions. The jsonParse
API parses the supplied string and returns an Ioto Json object which can be passed to the openaiResponse
API.
The response object is a JSON object that can be queried using the Ioto JSON library jsonGet
API. The output_text
field contains the complete response output text.
Consult the Response API for parameter details.
See the ai
app in the Ioto Agent source download for an example response.html
web page that uses the Response API.
References
Consult the OpenAI documentation for API details: