Skip to main content
skill CX Codex

llm-integration · rohitg00 — Claude Code skill: what it does, how to install

The llm-integration skill for Claude Code provides TypeScript patterns for Anthropic API integrations, including streaming, tool use, RAG, and token cost control.

Apache-2.0 ★ 2,858 updated 2026-05-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add rohitg00/awesome-claude-code-toolkit --skill llm-integration -a claude-code
Open on GitHub

What llm-integration does

This skill supplies Claude Code with practical TypeScript reference patterns built on @anthropic-ai/sdk. It provides concrete implementations for the standard client, event streaming via messages.stream, an automated tool-calling loop using tool_use and tool_result, and a document chunker with text overlap for retrieval pipelines.

The patterns target Claude models such as Haiku, Sonnet, and Opus, mapping each to specific workloads like text extraction, coding, or multi-step reasoning. Without explicit retry logic with exponential backoff and output sanitization, external API calls will cause unpredictable breaks in production workflows.

What it helps with

  • stream LLM responses token by token to standard output or UI
  • implement an agent loop handling tool execution and results
  • split text documents into overlapping chunks for vector search
  • pick suitable Claude model tiers to minimize API spending

Example prompts for the agent

  • Show the TypeScript tool use pattern for searching a database via Anthropic SDK
  • Create a document chunking function with overlap for RAG ingestion
  • Implement an agent loop that checks stop_reason and executes tool calls

How to install llm-integration

1Skills CLI (Vercel)

npx skills add rohitg00/awesome-claude-code-toolkit --skill llm-integration -a claude-code

2Manually: put the files in place

~/.claude/skills/llm-integration/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/llm-integration/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about llm-integration

How to install llm-integration in Claude Code?

Run npx skills add rohitg00/awesome-claude-code-toolkit --skill llm-integration -a claude-code or place the file into ~/.claude/skills/llm-integration/SKILL.md.

What does the llm-integration skill do?

It gives Claude Code direct reference patterns for TypeScript Anthropic API usage, covering streaming, function calling, RAG pipelines, and anti-pattern checklists.

Which SDK do the code snippets in this skill use?

All snippets are written in TypeScript specifically for the @anthropic-ai/sdk package.

Source text

SKILL.md · Apache-2.0
---
name: llm-integration
description: LLM integration patterns including API usage, streaming, function calling, RAG pipelines, and cost optimization
---

# LLM Integration

## API Client Pattern

```typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

async function generateResponse(
  userMessage: string,
  options?: { maxTokens?: number; temperature?: number }
): Promise<string> {
  const response = await client.messages.create({
    model: "claude-sonnet-4-20250514",
    max_tokens: options?.maxTokens ?? 1024,
    temperature: options?.temperature ?? 0,
    system: systemPrompt,
    messages: [{ role: "user", content: userMessage }],
  });

  const textBlock = response.content.find(block => block.type === "text");
  return textBlock?.text ?? "";
}
```

## Streaming Responses

```typescript
async function streamResponse(
  messages: Array<{ role: "user" | "assistant"; content: string }>,
  onChunk: (text: string) => void
): Promise<string> {
  const stream = client.messages.stream({
    model: "claude-sonnet-4-20250514",
    max_tokens: 4096,
    messages,
  });

  let fullText = "";

  for await (const event of stream) {
    if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
      onChunk(event.delta.text);
      fullText += event.delta.text;
    }
  }

  return fullText;
}

const response = await streamResponse(
  [{ role: "user", content: "Explain async/await in TypeScript" }],
  (chunk) => process.stdout.write(chunk)
);
```

## Function Calling (Tool Use)

```typescript
const tools: Anthropic.Tool[] = [
  {
    name: "search_database",
    description: "Search the product database by name, category, or price range",
    input_schema: {
      type: "object" as const,
      properties: {
        query: { type: "string", description: "Search query" },
        category: { type: "string", description: "Product category filter" },
        max_price: { type: "number", description: "Maximum price" },
      },
      required: ["query"],
    },
  },
];

async function agentLoop(userMessage: string): Promise<string> {
  const messages: Anthropic.MessageParam[] = [
    { role: "user", content: userMessage },
  ];

  while (true) {
    const response = await client.messages.create({
      model: "claude-sonnet-4-20250514",
      max_tokens: 4096,
      tools,
      messages,
    });

    if (response.stop_reason === "end_turn") {
      const text = response.content.find(b => b.type === "text");
      return text?.text ?? "";
    }

    const toolUse = response.content.find(b => b.type === "tool_use");
    if (!toolUse || toolUse.type !== "tool_use") break;

    const result = await executeToolCall(toolUse.name, toolUse.input);

    messages.push({ role: "assistant", content: response.content });
    messages.push({
      role: "user",
      content: [{ type: "tool_result", tool_use_id: toolUse.id, content: result }],
    });
  }

  return "";
}
```

## RAG Pipeline

```typescript
import { embed } from "./embeddings";

interface Chunk {
  id: string;
  text: string;
  metadata: Record<string, string>;
  embedding: number[];
}

async function retrieveAndGenerate(query: string): Promise<string> {
  const queryEmbedding = await embed(query);

  const relevantChunks = await vectorDb.search({
    vector: queryEmbedding,
    topK: 5,
    filter: { source: "documentation" },
  });

  const context = relevantChunks
    .map((chunk, i) => `[${i + 1}] ${chunk.text}`)
    .join("\n\n");

  const response = await client.messages.create({
    model: "claude-sonnet-4-20250514",
    max_tokens: 2048,
    system: `Answer questions using the provided context. Cite sources with [n] notation. If the context doesn't contain the answer, say so.`,
    messages: [
      {
        role: "user",
        content: `Context:\n${context}\n\nQuestion: ${query}`,
      },
    ],
  });

  return response.content[0].type === "text" ? response.content[0].text : "";
}
```

## Document Chunking

```typescript
function chunkDocument(
  text: string,
  options: { chunkSize: number; overlap: number }
): string[] {
  const { chunkSize, overlap } = options;
  const chunks: string[] = [];
  const sentences = text.split(/(?<=[.!?])\s+/);
  let current = "";

  for (const sentence of sentences) {
    if (current.length + sentence.length > chunkSize && current.length > 0) {
      chunks.push(current.trim());
      const words = current.split(" ");
      const overlapWords = words.slice(-Math.floor(overlap / 5));
      current = overlapWords.join(" ") + " " + sentence;
    } else {
      current += (current ? " " : "") + sentence;
    }
  }

  if (current.trim()) chunks.push(current.trim());
  return chunks;
}
```

## Cost Optimization

```typescript
function selectModel(task: TaskType): string {
  switch (task) {
    case "classification":
    case "extraction":
      return "claude-haiku-4-20250514";
    case "analysis":
    case "coding":
      return "claude-sonnet-4-20250514";
    case "complex-reasoning":
      return "claude-opus-4-5-20251101";
    default:
      return "claude-sonnet-4-20250514";
  }
}
```

Use the smallest model that achieves acceptable quality. Cache embeddings and responses where possible. Batch requests when latency is not critical.

## Anti-Patterns

- Sending entire documents when only relevant chunks are needed
- Not implementing retry logic with exponential backoff for API calls
- Ignoring token usage tracking (leads to unexpected costs)
- Using the most expensive model for simple classification tasks
- Not validating or sanitizing LLM output before using it in code
- Building RAG without evaluating retrieval quality first

## Checklist

- [ ] API calls wrapped with retry logic and error handling
- [ ] Streaming used for user-facing responses
- [ ] Function calling schemas include clear descriptions
- [ ] RAG chunks sized appropriately (500-1000 tokens) with overlap
- [ ] Model selection based on task complexity
- [ ] Token usage tracked and monitored for cost control
- [ ] LLM output validated before downstream use
- [ ] Embeddings cached to avoid redundant API calls

© rohitg00 · Apache-2.0 · rohitg00/awesome-claude-code-toolkit

Similar skills

All skills for AI and ML →

llm-integration by other authors comes first.

llm-integration OrchestKit llm-integration — a collection of 20 production rules for LLM workflows: strict function calling, SSE streaming endpoints, local Ollama deployments, and LoRA tuning. CX Codex +1 218installs llm-integration martinholovsky The llm-integration skill guides local LLM work with llama.cpp and Ollama, covering inference setup and prompt protection. Use it when model execution stays on your machine. CX Codex +1 239installs llm-application-dev MoizIbnYousaf llm-application-dev is a Claude Code skill for building with large language models across coding platforms. It includes prompt templates, API integration, RAG patterns, and error handling. CX Codex +1 467installs claude-sdk-integration-patterns manutej claude-sdk-integration-patterns is a Claude Code skill with integration patterns for Claude API and TypeScript SDK. Agents use them for streaming, tool execution and error handling in apps. CX Codex +1 437installs langchain4j-spring-boot-integration giuseppe-trisciuoglio langchain4j-spring-boot-integration configures LangChain4j in Spring Boot applications, setting up declarative @AiService interfaces, chat memory, and RAG pipelines with Spring Data. CX Codex +1 4,000installs ai-product coco-research ai-product guides building production AI features: structured schema validation, streaming UI patterns, prompt regression testing, and RAG pipelines. CX Codex +1 ★ 328repo stars llm-streaming-response-handler curiositech llm-streaming-response-handler builds production LLM streaming interfaces with Server-Sent Events and live token rendering. Helps add AbortController cancellation and stream error recovery. CX Codex +1 205installs mind-wasp-drone Legion Code Inc. mind-wasp-drone — a subagent for auditing and tuning everything LLM in your codebase: agent routing, prompt cascades, RAG, memory tiers, tracing, and streaming responses. Call it when you work on AI code, retrieval, or memory. CX Codex ★ 96repo stars

From the same set178

The whole set →
marketing-analyst marketing-analyst — a subagent that builds your marketing data infrastructure: multi-touch attribution, ROI by channel, customer acquisition cost, and lifetime value forecasting. Turns marketing decisions from guesswork into data. CX Codex ★ 2,858repo stars deep-dive deep-dive runs multi-step deep research in Claude Code using DAG query planning, parallel subagents, and gap iteration without external APIs. CX Codex +1 ★ 2,858repo stars patent-analyst patent-analyst — a Claude Code subagent that searches patent databases, analyzes prior art, maps IP landscapes, and assesses freedom to operate for technology products. CX Codex ★ 2,858repo stars workflow-director workflow-director — a subagent for Claude Code that orchestrates multi-step development workflows from start to finish with checkpoints and error recovery. CX Codex ★ 2,858repo stars security-researcher The security-researcher subagent investigates CVEs, maps attack surfaces, and models threats. Ask it to review project dependencies or draft actionable security findings. CX Codex ★ 2,858repo stars market-researcher market-researcher — a subagent for quantitative market intelligence in Claude Code: calculates market sizes using top-down and bottom-up methods, designs customer surveys, maps competitors, and identifies underserved segments. CX Codex ★ 2,858repo stars legal-advisor legal-advisor creates terms of service, privacy policies, and software licenses matching GDPR or CCPA standards. Connects legal requirements directly to technical safeguards. CX Codex ★ 2,858repo stars benchmarking-specialist The benchmarking-specialist subagent plans benchmarks, load tests, and system comparisons. Use it when performance claims need repeatable measurements and a documented method. CX Codex ★ 2,858repo stars

Project sponsors

Companies that keep this analytics open