Skip to main content
This page gives a model in the AI SDK by Vercel the PartFinder API as tools. generateText runs each tool call and sends the result back until the model answers.

Install

Save partfinder-tools.mjs next to your code. It builds the tools from the OpenAPI document and makes each call with the key from PARTFINDER_API_KEY.

Give the model the tools

agent.mjs
jsonSchema wraps each operation’s JSON Schema for inputSchema. stopWhen: isStepCount(5) lets the model make tool calls for up to five steps. A model id such as anthropic/claude-sonnet-5.5 runs through the AI Gateway, which reads AI_GATEWAY_API_KEY. Any other gateway the AI SDK supports works the same way: only the model line changes.

Jobs and refusals

searchParts, compareParts and analyzeBom start a job. callTool waits for the job and returns the finished result, so the model does not need to poll. A refused call returns the API’s JSON with its error code and summary, and the model reads it like any other result. See AI agent integration for the rest of the rules.