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

> ## Agent Instructions
> The PartFinder API is served at https://api.partfinder.dev. Authenticate with `Authorization: Bearer $PARTFINDER_API_KEY`; create an account at https://console.partfinder.dev/sign-up and pick pay as you go or a monthly or yearly plan (see https://partfinder.dev/pricing), then create a key. Pay as you go starts with 100 free credits, once per person and per company.
> Install the PartFinder agent skill with `npx skills add https://docs.partfinder.dev` (skill file: https://docs.partfinder.dev/skill.md).
> The OpenAPI document at https://api.partfinder.dev/v1/openapi.json is the source of truth for request and response schemas.
> What each call costs and current plans: https://api.partfinder.dev/llms.txt.

# Use PartFinder with the AI SDK by Vercel

> Give a model in the AI SDK by Vercel the PartFinder API as tools built from the OpenAPI document with jsonSchema.

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

```bash theme={null}
npm install ai
export AI_GATEWAY_API_KEY="..."
export PARTFINDER_API_KEY="ak_..."
```

Save [`partfinder-tools.mjs`](https://docs.partfinder.dev/ai-agent-integration#build-the-tools-from-the-openapi-document) next to
your code. It builds the tools from the [OpenAPI document](https://api.partfinder.dev/v1/openapi.json)
and makes each call with the key from `PARTFINDER_API_KEY`.

## Give the model the tools

```js agent.mjs theme={null}
import { generateText, tool, jsonSchema, isStepCount } from "ai";
import { operations, callTool } from "./partfinder-tools.mjs";

const tools = Object.fromEntries(
  operations.map((op) => [
    op.name,
    tool({
      description: op.description,
      inputSchema: jsonSchema(op.parameters),
      execute: (input) => callTool(op.name, input),
    }),
  ]),
);

const result = await generateText({
  model: "anthropic/claude-sonnet-5.5",
  tools,
  stopWhen: isStepCount(5),
  prompt: "Is my PartFinder API key working?",
});

console.log(result.text);
```

`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](https://docs.partfinder.dev/ai-agent-integration.md)
for the rest of the rules.


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