# Add Ai Provider

> Implement the image-generation provider interface for a new provider (fal, Replicate, direct OpenAI, ...). Use when swapping or adding an AI provider.

- **Type:** Skill
- **Install:** `agentstack add skill-nikandr-surkov-ai-saas-starter-add-ai-provider`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [nikandr-surkov](https://agentstack.voostack.com/s/nikandr-surkov)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [nikandr-surkov](https://github.com/nikandr-surkov)
- **Source:** https://github.com/nikandr-surkov/ai-saas-starter/tree/main/.claude/skills/add-ai-provider
- **Website:** https://ai-saas-starter-six.vercel.app

## Install

```sh
agentstack add skill-nikandr-surkov-ai-saas-starter-add-ai-provider
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Add an AI provider

The contract lives in `src/lib/ai/provider.ts`:

```ts
generateImage({ prompt, userId }): Promise;
```

The default implementation is `src/lib/ai/gateway.ts` (Vercel AI Gateway).
Read both files before writing anything.

## Steps

1. **Ask the user first** — a new provider almost always means a new
   dependency, and dependencies need approval (AGENTS.md).
2. Create `src/lib/ai/.ts` exporting an object that satisfies the
   `ImageProvider` interface. Keep it thin: call the API, normalize the
   response to `{ url, width, height, model }`, throw on failure.
3. Config comes from env. Add the new vars to:
   - `src/lib/env.ts` (Zod schema, optional unless the provider is active)
   - `.env.example` (with a comment and a link to where keys come from)
4. Wire selection where the provider is chosen (see how `gateway.ts` and the
   `AI_MOCK` flag are dispatched) — selection stays env-driven, no
   provider conditionals in UI or actions.
5. **Do not touch the credits flow.** The generate action already spends
   before calling the provider and refunds on failure. Your provider just
   throws on error; the action handles money.
6. Test: unit-test the response normalization with a mocked HTTP layer.
   Then run the e2e generate flow with the real provider once, manually.

## Scope note

This repo intentionally ships one provider. Multi-provider image/video/audio
with job queues, auto-refunds and gallery storage is what the Pro version is
for (https://nikandr.com) — don't rebuild it ad hoc here.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [nikandr-surkov](https://github.com/nikandr-surkov)
- **Source:** [nikandr-surkov/ai-saas-starter](https://github.com/nikandr-surkov/ai-saas-starter)
- **License:** MIT
- **Homepage:** https://ai-saas-starter-six.vercel.app

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-nikandr-surkov-ai-saas-starter-add-ai-provider
- Seller: https://agentstack.voostack.com/s/nikandr-surkov
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
