You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a
.env file with the name WRITER_API_KEY.Tool structure
Use the LLM tool to delegate specific tasks to another model when using the chat endpoint. Using tool calling, you can specify the model you want to use for a given task. When the primary chat model calls the LLM tool based on the user’s input, it signals it in the chat API response. To use the LLM tool, add it to thetools array in your chat-completion endpoint request.
The LLM tool object has the following structure:
To help the model understand when to use the tool, follow these best practices for the
function.description parameter:- Indicate that the tool is a function that invokes an LLM
- Specify the model’s purpose and capabilities
- Describe when the tool should be used
“A function that invokes the LLM identified by the given model for detailed analysis. Any user request requiring in-depth analysis should use this tool.”
You can only pass one prebuilt tool in the
tools array at a time. However, you can pass multiple custom tools in the same request.Prebuilt tools are:Response format
When a chat completion uses the LLM tool, the response from the LLM tool is in thellm_data object. The llm_data object contains the following fields:
Below is an example of the full response to a chat completion request that uses the LLM tool with an external model.
Usage example
Here’s an example of how to use the LLM tool in your application. This example delegates detailed questions to an external model.Create a tools array containing an LLM tool
To use the LLM tool, create atools array that specifies the model you want to use.
Send the request using chat completions
Add the tools array to the chat endpoint call along with your array of messages. Settingtool_choice to auto allows the model to choose when to use the LLM tool, based on the user’s question and the description of the tool.
This example streams the response as the model generates it.
If you are unfamiliar with the chat completions endpoint or streaming vs. non-streaming responses, learn more in the chat completion guide.