agentleFS
nikandr-surkovnikandr-surkov/ai-saas-starter/.claude/skills/add-ai-provider/SKILL.md

add-ai-provider

Skill16 starsChanged 5 months agoMITView on GitHub

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

  • Reads credentials

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read both files before writing anything.

    line 15
  2. Very specific:

    Create src/lib/ai/<provider>.ts exporting an object that satisfies the ImageProvider interface.

    line 21
  3. Distinctive:

    Test: unit-test the response normalization with a mocked HTTP layer.

    line 33

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Add an AI provider

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

generateImage({ prompt, userId }): Promise<{ url; width; height; model }>;

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/<provider>.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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.