> ## Documentation Index
> Fetch the complete documentation index at: https://www.usenotra.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Function calling

> Let writer-0.1 call your functions on Chat Completions and the Responses API: offering tools, tool_choice, reading calls and sending results back.

writer-0.1 calls functions on both APIs. A call only ever names a function from the request's `tools`. With no tools, or with `tool_choice: "none"`, the model answers in text.

## Chat Completions

Offer functions in `tools`. Set `tool_choice` to `auto` (the default), `none`, `required`, or a named function to force that call. Set `parallel_tool_calls: false` to ask for at most one call.

```ts theme={"system"}
const tools = [
  {
    type: "function" as const,
    function: {
      name: "get_release",
      description: "Get the merged pull requests for a release.",
      parameters: {
        type: "object",
        properties: { version: { type: "string" } },
        required: ["version"],
      },
    },
  },
];

const messages: OpenAI.ChatCompletionMessageParam[] = [
  { role: "user", content: "Write the changelog for v2.4." },
];

const first = await client.chat.completions.create({ model: "writer-0.1", messages, tools });
const message = first.choices[0].message;

if (message.tool_calls) {
  messages.push(message);
  for (const call of message.tool_calls) {
    const args = JSON.parse(call.function.arguments);
    messages.push({
      role: "tool",
      tool_call_id: call.id,
      content: JSON.stringify(await getRelease(args.version)),
    });
  }
  const answer = await client.chat.completions.create({ model: "writer-0.1", messages, tools });
  console.log(answer.choices[0].message.content);
}
```

When the model calls functions, `finish_reason` is `tool_calls` and the message carries `tool_calls` in OpenAI's format. `arguments` is a JSON string. Streamed calls arrive as `delta.tool_calls`.

Send the assistant message with its `tool_calls` and one `tool` message per call back in the history. Only function tools are sent to the model; other tool types are ignored. A tool call in the history whose arguments aren't valid JSON, or a custom tool call, reaches the model as text.

> [!NOTE]
>
> The legacy `functions` parameter is ignored, and a legacy `function_call` that names a function is rejected with 400 `unsupported_parameter`. Use `tools` and `tool_choice`.

## Responses API

Functions are flat: `{type: "function", name, description, parameters, strict}`. `tool_choice` takes `"auto"`, `"none"`, `"required"` or `{type: "function", name}`.

```ts theme={"system"}
const tools = [
  {
    type: "function" as const,
    name: "get_release",
    description: "Get the merged pull requests for a release.",
    parameters: {
      type: "object",
      properties: { version: { type: "string" } },
      required: ["version"],
    },
    strict: true,
  },
];

const input: OpenAI.Responses.ResponseInput = [
  { role: "user", content: "Write the changelog for v2.4." },
];

const first = await client.responses.create({ model: "writer-0.1", input, tools });
const calls = first.output.filter((item) => item.type === "function_call");

for (const call of calls) {
  input.push(call, {
    type: "function_call_output",
    call_id: call.call_id,
    output: JSON.stringify(await getRelease(JSON.parse(call.arguments).version)),
  });
}

const answer = await client.responses.create({ model: "writer-0.1", input, tools });
console.log(answer.output_text);
```

Calls are `function_call` items in `response.output`, and `arguments` is a JSON string. The Responses API keeps no conversation state (`previous_response_id` isn't supported), so send the earlier input and output items each time, followed by a `function_call_output` for each call. Notra still keeps every request in your workspace's Logs; see [Data and privacy](https://www.usenotra.com/docs/platform/account/data-and-privacy.md). Only message text counts toward the SDK's `output_text`.

Function arguments stream as `response.function_call_arguments.delta` and `response.function_call_arguments.done`. Tools other than functions, like built-in and custom tools, are rejected with 400 `unsupported_parameter`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.