agentleFS
Dokkabei97Dokkabei97/forged-claude-code/skills/cto/ai-integration/SKILL.md

ai-integration

Skill2 starsChanged 9 months agoMITView on GitHub

Generates LLM API integration code for OpenAI, Anthropic, and Google. Includes prompt engineering patterns, streaming responses, error handling, cost estimation, and RAG pipeline setup.

  • Reads credentials
  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Rule of thumb: Start with cheaper models, upgrade only when quality demands it.

    line 151

≈ “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.

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

AI Integration - LLM API Integration Guide

Overview

Generates production-ready LLM API integration code. From basic chat completion to RAG pipelines, with cost tracking and error handling.


1. When to Apply

TriggerBehavior
Adding AI/LLM featuresFull integration setup
"OpenAI", "Anthropic", "RAG"Provider-specific integration
AI feature architecturePattern recommendation

2. Provider Quick Start

OpenAI (TypeScript)

import OpenAI from 'openai'

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })

async function chat(prompt: string): Promise<string> {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: prompt }],
    max_tokens: 1000,
  })
  return response.choices[0].message.content ?? ''
}

Anthropic (TypeScript)

import Anthropic from '@anthropic-ai/sdk'

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })

async function chat(prompt: string): Promise<string> {
  const response = await anthropic.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    messages: [{ role: 'user', content: prompt }],
  })
  return response.content[0].type === 'text' ? response.content[0].text : ''
}

Streaming Response (Next.js)

// app/api/chat/route.ts
import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'

export async function POST(req: Request) {
  const { messages } = await req.json()
  const result = streamText({
    model: openai('gpt-4o'),
    messages,
  })
  return result.toDataStreamResponse()
}

3. Common Patterns

Structured Output

import { z } from 'zod'

const schema = z.object({
  sentiment: z.enum(['positive', 'negative', 'neutral']),
  confidence: z.number().min(0).max(1),
  summary: z.string(),
})

const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: text }],
  response_format: { type: 'json_object' },
})
const result = schema.parse(JSON.parse(response.choices[0].message.content!))

RAG Pipeline (Simplified)

1. Document ingestion → chunk → embed → store in vector DB
2. Query → embed query → similarity search → retrieve chunks
3. Augment prompt with retrieved context → generate response

Error Handling & Retry

async function callWithRetry<T>(
  fn: () => Promise<T>,
  maxRetries = 3,
  baseDelay = 1000
): Promise<T> {
  for (let i = 0; i <= maxRetries; i++) {
    try {
      return await fn()
    } catch (error: any) {
      if (i === maxRetries) throw error
      if (error.status === 429 || error.status >= 500) {
        await new Promise(r => setTimeout(r, baseDelay * Math.pow(2, i)))
        continue
      }
      throw error // Don't retry client errors
    }
  }
  throw new Error('Unreachable')
}

4. Cost Estimation

ModelInput (1K tokens)Output (1K tokens)
GPT-4o$0.0025$0.01
GPT-4o-mini$0.00015$0.0006
Claude Sonnet$0.003$0.015
Claude Haiku$0.0008$0.004

Rule of thumb: Start with cheaper models, upgrade only when quality demands it.


5. Tool Coordination

ToolPurpose
WriteGenerate integration code
ReadAnalyze existing codebase
BashInstall SDKs (npm install openai)

6. Boundaries

Will:

  • Generate LLM API integration code for major providers
  • Include streaming, structured output, and error handling patterns
  • Provide cost estimation and model selection guidance
  • Set up basic RAG pipeline structure

Will Not:

  • Train or fine-tune models
  • Set up vector databases (mention options, don't configure)
  • Build full AI products (provides building blocks)
  • Guarantee prompt quality (use prompt-engineer agent)

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.