# Vercel AI SDK

> Give your own agent Yap Factory tools: search creators, run campaigns, keep deals moving and schedule posts. `@yapfactory/ai-sdk` turns every [API operation](https://yapfactory.com/developers/api.md) into an AI SDK tool.

Building inside ChatGPT or Claude instead? Use the [MCP server](https://yapfactory.com/developers/mcp.md): no code.

## Install

pnpm:

```bash
pnpm add @yapfactory/ai-sdk ai
```

npm:

```bash
npm install @yapfactory/ai-sdk ai
```

yarn:

```bash
yarn add @yapfactory/ai-sdk ai
```

bun:

```bash
bun add @yapfactory/ai-sdk ai
```

Works with AI SDK 5, 6 and 7, in Node 18 or later and on edge runtimes.

## Get an API key

In Yap Factory, open **Settings → AI agents → Make an API key**, then set it as `YAPFACTORY_API_KEY`. The tools act as you: a brand key gets the brand tools, a creator key the creator tools.

.env:

```bash
YAPFACTORY_API_KEY=yf_live_...
```

Acting for other people, each with their own account? Get each person's token with [OAuth](https://yapfactory.com/developers/oauth.md) and pass it as `apiKey`.

## Quick start

```ts
import { generateText, isStepCount } from 'ai';
import { yapfactoryTools } from '@yapfactory/ai-sdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Find three UGC creators for my skincare campaign and say why each one fits.',
  tools: yapfactoryTools({ access: 'read' }),
  stopWhen: isStepCount(5),
});

console.log(text);
```

`access: 'read'` gives only the tools that change nothing, which suits a first try.

## Ask before anything reaches people

Some tools tell other people straight away: publishing a campaign, inviting creators, messages, answering invites and scheduled posts. `createYapFactory()` returns a `toolApproval` map (AI SDK 7) that marks each of them `user-approval`, so the AI SDK stops and asks your user before they run. On AI SDK 5 or 6, use `access: 'write'`, which leaves those tools out.

```ts
import { generateText, isStepCount } from 'ai';
import { createYapFactory } from '@yapfactory/ai-sdk';

const yapfactory = createYapFactory();

const result = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Draft a UGC campaign for my app, then invite the three best-fitting creators.',
  tools: yapfactory.tools,
  toolApproval: yapfactory.toolApproval, // invites, publishing, messages and posts wait for a yes
  stopWhen: isStepCount(8),
});

// Calls that need a yes come back as tool-approval-request parts.
const waiting = result.steps.flatMap((s) => s.content).filter((p) => p.type === 'tool-approval-request');
```

> No tool moves money. Starting a deal (the brand's card is charged) and approving a draft (the creator is paid) return a link to finish on yapfactory.com.

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `apiKey` | `YAPFACTORY_API_KEY` | An API key (`yf_live_…`) or an OAuth access token. |
| `access` | `'all'` | `'read'`: only tools that change nothing. `'write'`: also your own drafts, briefs and scheduled posts. `'all'`: also tools that reach people and the payment links. |
| `side` | both | `'brand'` or `'creator'`: only that side's tools (shared tools stay). |
| `only` | every tool | A list of tool names, such as `['searchCreators', 'getCreator']`. |
| `baseURL` | `https://yapfactory.com/api/v1` | Another Yap Factory host, for testing. |
| `headers`, `fetch` | none | Extra headers, or your own fetch. |

## Results and errors

- Each tool returns the API's JSON: `{ data }`, and lists also carry `nextCursor` and `hasMore`. Money is `{ minor, currency, formatted }`.
- When the API refuses a call, the tool returns `{ error: { code, message, status, requestId } }` instead of throwing, so the model can tell the person what happened. `message` is written for people. See [errors](https://yapfactory.com/developers/errors.md).
- Calls that change something send an `Idempotency-Key` made from the tool call's id, so a retried step never runs twice.
- [Rate limits](https://yapfactory.com/developers/pagination.md) are per key: 120 reads, 20 writes and 10 calls that reach people a minute.

## The tools

One tool per API operation, named in camelCase. Each links to its reference page.

| Tool | For | Kind |
| --- | --- | --- |
| [`getAccount`](https://yapfactory.com/developers/api/get_account.md) | Everyone | Reads |
| [`listDeals`](https://yapfactory.com/developers/api/list_deals.md) | Everyone | Reads |
| [`getDeal`](https://yapfactory.com/developers/api/get_deal.md) | Everyone | Reads |
| [`sendDealMessage`](https://yapfactory.com/developers/api/send_deal_message.md) | Everyone | Reaches people: asks first |
| [`searchCreators`](https://yapfactory.com/developers/api/search_creators.md) | Brands | Reads |
| [`getCreator`](https://yapfactory.com/developers/api/get_creator.md) | Brands | Reads |
| [`listProducts`](https://yapfactory.com/developers/api/list_products.md) | Brands | Reads |
| [`listCampaigns`](https://yapfactory.com/developers/api/list_campaigns.md) | Brands | Reads |
| [`getCampaign`](https://yapfactory.com/developers/api/get_campaign.md) | Brands | Reads |
| [`createCampaignDraft`](https://yapfactory.com/developers/api/create_campaign_draft.md) | Brands | Your own things |
| [`updateCampaignBrief`](https://yapfactory.com/developers/api/update_campaign_brief.md) | Brands | Your own things |
| [`publishCampaign`](https://yapfactory.com/developers/api/publish_campaign.md) | Brands | Reaches people: asks first |
| [`setCampaignStatus`](https://yapfactory.com/developers/api/set_campaign_status.md) | Brands | Reaches people: asks first |
| [`inviteCreators`](https://yapfactory.com/developers/api/invite_creators.md) | Brands | Reaches people: asks first |
| [`passOnCreator`](https://yapfactory.com/developers/api/pass_on_creator.md) | Brands | Reaches people: asks first |
| [`requestRevision`](https://yapfactory.com/developers/api/request_revision.md) | Brands | Reaches people: asks first |
| [`browseCampaigns`](https://yapfactory.com/developers/api/browse_campaigns.md) | Creators | Reads |
| [`viewCampaignBrief`](https://yapfactory.com/developers/api/view_campaign_brief.md) | Creators | Reads |
| [`askToJoin`](https://yapfactory.com/developers/api/ask_to_join.md) | Creators | Reaches people: asks first |
| [`respondToInvite`](https://yapfactory.com/developers/api/respond_to_invite.md) | Creators | Reaches people: asks first |
| [`listPostAccounts`](https://yapfactory.com/developers/api/list_post_accounts.md) | Brands | Reads |
| [`getPostAccount`](https://yapfactory.com/developers/api/get_post_account.md) | Brands | Reads |
| [`listPostableVideos`](https://yapfactory.com/developers/api/list_postable_videos.md) | Brands | Reads |
| [`preparePostUpload`](https://yapfactory.com/developers/api/prepare_post_upload.md) | Brands | Your own things |
| [`schedulePost`](https://yapfactory.com/developers/api/schedule_post.md) | Brands | Reaches people: asks first |
| [`listPosts`](https://yapfactory.com/developers/api/list_posts.md) | Brands | Reads |
| [`updatePost`](https://yapfactory.com/developers/api/update_post.md) | Brands | Your own things |
| [`cancelPost`](https://yapfactory.com/developers/api/cancel_post.md) | Brands | Your own things |
| [`startDeal`](https://yapfactory.com/developers/api/start_deal.md) | Brands | Returns a link |
| [`approveDraft`](https://yapfactory.com/developers/api/approve_draft.md) | Brands | Returns a link |

## Source and support

- npm: [@yapfactory/ai-sdk](https://www.npmjs.com/package/@yapfactory/ai-sdk). MIT licence.
- Source: [github.com/shehrum/yapfactory-plugin](https://github.com/shehrum/yapfactory-plugin/tree/main/ai-sdk).
- Questions: [support@yapfactory.com](mailto:support@yapfactory.com).

---

HTML version: https://yapfactory.com/developers/ai-sdk
