add-ai-provider
Skill23 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
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/billing.mdcCursor rule
- .cursor/rules/core.mdcCursor rule
- add-featureSkill
- db-migrationSkill
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
- Distinctive: line 15
Read both files before writing anything.
- Very specific: line 21
Create src/lib/ai/<provider>.ts exporting an object that satisfies the ImageProvider interface.
- Distinctive: line 33
Test: unit-test the response normalization with a mocked HTTP layer.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
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
- Ask the user first — a new provider almost always means a new dependency, and dependencies need approval (AGENTS.md).
- Create
src/lib/ai/<provider>.tsexporting an object that satisfies theImageProviderinterface. Keep it thin: call the API, normalize the response to{ url, width, height, model }, throw on failure. - 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)
- Wire selection where the provider is chosen (see how
gateway.tsand theAI_MOCKflag are dispatched) — selection stays env-driven, no provider conditionals in UI or actions. - 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.
- 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.
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
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.

