Follow this 10-minute tutorial to understand how the completions endpoint works
This step-by-step guide shows how to call the POST /completions endpoint, interpret the response, and integrate it into your application.
For more code examples, check out the POST /completions endpoint reference.
Before you start, you will need:
Get your API key
Go to Accounts -> Settings -> API Keys and copy your key — it will be used for authentication via Bearer Token.
Choose an HTTP client
You can use Postman, Insomnia, or cURL (example below). Make sure the client is installed and properly configured.
The POST /completions endpoint generates text based on a prompt. See an example request below:
If an error occurs, check if your key is correct and if the endpoint is accessible.
A typical response (HTTP 200) might be:
tool_call
with a Custom FunctionYou can also instruct the model to invoke tools (functions) in a structured way using the toolChoice
field and providing a list of tools
. This is useful when you want the model to trigger a specific functionality, such as fetching information or executing an external action based on user input.
See an example:
You can use this approach to connect the model with specific actions, such as fetching external data, calculating values, or executing custom commands.
toolCall
When the model decides to use the tool, the response will include a toolCall
field with the filled arguments:
Now that you have the extracted arguments, your backend can execute the actual function (fetch_weather_forecast
) with the provided parameters. This flow allows the model to act as a natural interface for your internal functionalities.
Test this example by replacing fetch_weather_forecast
with specific functions from your domain — such as scheduling a meeting, querying a lead, or fetching real-time data.
Follow this 10-minute tutorial to understand how the completions endpoint works
This step-by-step guide shows how to call the POST /completions endpoint, interpret the response, and integrate it into your application.
For more code examples, check out the POST /completions endpoint reference.
Before you start, you will need:
Get your API key
Go to Accounts -> Settings -> API Keys and copy your key — it will be used for authentication via Bearer Token.
Choose an HTTP client
You can use Postman, Insomnia, or cURL (example below). Make sure the client is installed and properly configured.
The POST /completions endpoint generates text based on a prompt. See an example request below:
If an error occurs, check if your key is correct and if the endpoint is accessible.
A typical response (HTTP 200) might be:
tool_call
with a Custom FunctionYou can also instruct the model to invoke tools (functions) in a structured way using the toolChoice
field and providing a list of tools
. This is useful when you want the model to trigger a specific functionality, such as fetching information or executing an external action based on user input.
See an example:
You can use this approach to connect the model with specific actions, such as fetching external data, calculating values, or executing custom commands.
toolCall
When the model decides to use the tool, the response will include a toolCall
field with the filled arguments:
Now that you have the extracted arguments, your backend can execute the actual function (fetch_weather_forecast
) with the provided parameters. This flow allows the model to act as a natural interface for your internal functionalities.
Test this example by replacing fetch_weather_forecast
with specific functions from your domain — such as scheduling a meeting, querying a lead, or fetching real-time data.