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

# Tool Calling

> Use AI SDK tools with Tensormesh chat models.

Tool calling lets the model choose arguments for functions defined by your application. With `tensormesh(modelId)`, AI SDK tool calls are sent through `/v1/chat/completions`.

```ts theme={null}
import { streamText, stepCountIs, tool } from "ai";
import { tensormesh } from "@tensormesh/ai-sdk-provider";
import { z } from "zod";

const modelId = "Qwen/Qwen3-Coder-30B-A3B-Instruct";

const result = streamText({
  model: tensormesh(modelId),
  prompt: "What is 128 multiplied by 7? Use the calculator tool.",
  tools: {
    calculator: tool({
      description: "Run one arithmetic operation.",
      inputSchema: z.object({
        operation: z.enum(["add", "subtract", "multiply", "divide"]),
        left: z.number(),
        right: z.number(),
      }),
      execute: async ({ operation, left, right }) => {
        switch (operation) {
          case "add":
            return { result: left + right };
          case "subtract":
            return { result: left - right };
          case "multiply":
            return { result: left * right };
          case "divide":
            return { result: right === 0 ? null : left / right };
        }
      },
    }),
  },
  prepareStep: async ({ stepNumber }) =>
    stepNumber === 0
      ? {
          toolChoice: modelId.toLowerCase().includes("gpt-oss")
            ? "auto"
            : "required",
        }
      : {},
  stopWhen: stepCountIs(3),
});

for await (const text of result.textStream) {
  process.stdout.write(text);
}
```

Use `toolChoice: "auto"` for GPT OSS models. Use `toolChoice: "required"` when the selected model supports it and you want to force a tool call in a demo or test.

## Responses API Tool Calls

The package also exposes raw `/v1/responses` helpers. When you call the Responses API directly, use the endpoint payload shape and include a boolean `strict` value for function tools.
Responses API tool-calling support is model-dependent; `lukealonso/GLM-5.1-NVFP4-MTP` does not currently support tool calling through `/v1/responses`.

```ts theme={null}
import { tensormesh } from "@tensormesh/ai-sdk-provider";

const response = await tensormesh.responses.create({
  model: "openai/gpt-oss-20b",
  input: "What is the weather in Bangkok? Use the weather tool.",
  tools: [
    {
      type: "function",
      name: "weather",
      description: "Return weather for a city.",
      strict: true,
      parameters: {
        type: "object",
        properties: {
          city: { type: "string" },
        },
        required: ["city"],
        additionalProperties: false,
      },
    },
  ],
  tool_choice: "auto",
});

console.log(response);
```
