Documentation
    Preparing search index...

    Function toVercelTools

    • Convert typia controllers to Vercel AI SDK tools.

      Transforms TypeScript class methods via typia.llm.controller<Class>() or OpenAPI operations via HttpLlm.controller() into Vercel AI SDK tools that can be used with any LLM provider (OpenAI, Anthropic, Google, etc.).

      Every tool call is validated by typia. If the LLM provides invalid arguments, returns a validation error formatted by LlmJson.stringify so the LLM can auto-correct in the next turn.

      import { generateText } from "ai";
      import { openai } from "@ai-sdk/openai";
      import typia from "typia";
      import { toVercelTools } from "@typia/vercel";

      class Calculator {
      /&#42;&#42; Add two numbers together. &#42;/
      add(props: { a: number; b: number }): { value: number } {
      return { value: props.a + props.b };
      }
      }

      const controller = typia.llm.controller<Calculator>("calc", new Calculator());
      const tools = toVercelTools({ controllers: [controller] });

      const result = await generateText({
      model: openai("gpt-4o"),
      tools,
      prompt: "What is 15 + 27?",
      });
      import { anthropic } from "@ai-sdk/anthropic";
      import { toVercelTools } from "@typia/vercel";
      import { generateText } from "ai";

      const result = await generateText({
      model: anthropic("claude-sonnet-4-20250514"),
      tools: toVercelTools({ controllers: [controller] }),
      prompt: "Calculate 100 * 50",
      });
      import { openai } from "@ai-sdk/openai";
      import { HttpLlm } from "@typia/utils";
      import { toVercelTools } from "@typia/vercel";
      import { generateText } from "ai";

      const controller = HttpLlm.controller({
      name: "shopping",
      document: await fetch("https://api.example.com/swagger.json").then(
      (r) => r.json(),
      ),
      connection: { host: "https://api.example.com" },
      });

      const result = await generateText({
      model: openai("gpt-4o"),
      tools: toVercelTools({ controllers: [controller] }),
      prompt: "Search for laptops under $1000",
      });

      Parameters

      • props: { controllers: (IHttpLlmController | ILlmController<any>)[]; prefix?: boolean }

        Conversion properties

        • controllers: (IHttpLlmController | ILlmController<any>)[]

          List of controllers to convert to Vercel tools.

          • ILlmController: from typia.llm.controller<Class>(), converts all methods of the class to tools
          • IHttpLlmController: from HttpLlm.controller(), converts all operations from OpenAPI document to tools
        • Optionalprefix?: boolean

          Whether to prefix tool names with controller name.

          If true, tool names are formatted as {controller}_{function}. If false, only the function name is used (may cause conflicts).

          false
          

      Returns Record<string, Tool>

      Record of Vercel AI SDK Tools keyed by tool name

      Jeongho Nam - https://github.com/samchon