llm-integration
Skill1 starsChanged 9 months agoApache-2.0View on GitHub
Integrate OpenAI and Anthropic APIs with streaming, structured output, tool calling, token management, and cost optimization
- Reads credentials
6 other projects use a version of this.
Adopted by
Most recently taken up by
- SkotAlexsander/skillstheir own version, first seen Sep 16, 2026
- nimadorostkar/Claude-Skills-collectiontheir own version, first seen Jul 14, 2026
- tdyzzsp47/claude-skillstheir own version, first seen Jun 12, 2026
- ThuPhuong1010/claude-factorytheir own version, first seen Mar 29, 2026
- rohitg00/awesome-claude-code-toolkittheir own version, first seen Feb 4, 2026
- martinholovsky/claude-skills-generatortheir own version, first seen Nov 25, 2025
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- rohitg00/awesome-claude-code-toolkit★ 2.7ksame name
- martinholovsky/claude-skills-generator★ 47same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- SkotAlexsander/skills★ 1same name
- tdyzzsp47/claude-skills★ 1same name
- ThuPhuong1010/claude-factory★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository73 other files it gives its agents.
- accessibility-wcagSkill
- api-designSkill
- api-testingSkill
- asset-optimizationSkill
- audio-systemsSkill
- aws-essentialsSkill
- ci-cd-pipelinesSkill
- codebase-analysisSkill
- code-reviewerSkill
- container-securitySkill
- cost-optimizationSkill
- database-designSkill
- data-visualizationSkill
- doc-generationSkill
- docker-kubernetesSkill
- docxSkill
- email-notificationsSkill
- env-configSkill
- flutter-mobileSkill
- framer-motionSkill
- frontend-code-reviewSkill
- frontend-designSkill
- fullstack-developerSkill
- game-enginesSkill
- gameplay-designSkill
- game-programming-languagesSkill
- game-serversSkill
- git-workflowSkill
- godot-4Skill
- golang-proSkill
- go-linter-configurationSkill
- graphics-renderingSkill
- i18n-localizationSkill
- incident-responseSkill
- level-designSkill
- local-securitySkill
- memory-managementSkill
- monetization-systemsSkill
- monitoring-observabilitySkill
- multiplayer-netcodeSkill
- nextjs-16Skill
- notebooklm-researchSkill
- npm-packageSkill
- oauth-authSkill
- particle-systemsSkill
- performance-optimizationSkill
- playwright-testingSkill
- postgres-advancedSkill
- programming-architectureSkill
- project-migrationSkill
- publishing-platformsSkill
- python-best-practicesSkill
- react-nativeSkill
- redis-patternsSkill
- refactoring-patternsSkill
- remotion-best-practicesSkill
- rust-best-practicesSkill
- scraping-automationSkill
- security-reviewSkill
- seo-metaSkill
- The first 60 shown.
The file
Files
LLM Integration Skill
Integrate Large Language Models (OpenAI, Anthropic) into applications with proper streaming, structured outputs, tool calling, prompt engineering, token management, and error handling.
API Configuration and Client Setup
BAD: Hardcoded credentials, no validation
const openai = new OpenAI({
apiKey: "sk-proj-abc123" // Hardcoded key
});
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY // No validation
});GOOD: Environment validation, typed configuration
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';
interface LLMConfig {
openaiKey?: string;
anthropicKey?: string;
maxRetries: number;
timeout: number;
}
function validateConfig(config: LLMConfig): void {
if (!config.openaiKey && !config.anthropicKey) {
throw new Error('At least one API key (OPENAI_API_KEY or ANTHROPIC_API_KEY) required');
}
if (config.timeout < 1000) {
throw new Error('Timeout must be at least 1000ms');
}
}
const config: LLMConfig = {
openaiKey: process.env.OPENAI_API_KEY,
anthropicKey: process.env.ANTHROPIC_API_KEY,
maxRetries: 3,
timeout: 60000
};
validateConfig(config);
const openai = config.openaiKey ? new OpenAI({
apiKey: config.openaiKey,
maxRetries: config.maxRetries,
timeout: config.timeout
}) : null;
const anthropic = config.anthropicKey ? new Anthropic({
apiKey: config.anthropicKey,
maxRetries: config.maxRetries,
timeout: config.timeout
}) : null;Streaming Responses
BAD: No streaming, blocks UI, no error handling
async function chat(prompt: string) {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: prompt }]
});
return response.choices[0].message.content;
}GOOD: Streaming with error handling and token tracking
async function* streamChat(
prompt: string,
onToken?: (token: string) => void
): AsyncGenerator<string, void, unknown> {
try {
const stream = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: prompt }],
stream: true,
stream_options: { include_usage: true }
});
let totalTokens = 0;
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content;
if (delta) {
onToken?.(delta);
yield delta;
}
if (chunk.usage) {
totalTokens = chunk.usage.total_tokens;
}
}
console.log(`Total tokens used: ${totalTokens}`);
} catch (error) {
if (error instanceof OpenAI.APIError) {
throw new Error(`OpenAI API error (${error.status}): ${error.message}`);
}
throw error;
}
}
// Usage
for await (const token of streamChat('Explain streaming', console.log)) {
process.stdout.write(token);
}GOOD: Anthropic streaming with tool use
async function* streamAnthropicWithTools(
prompt: string,
tools: Anthropic.Tool[]
): AsyncGenerator<string, any, unknown> {
const stream = await anthropic.messages.stream({
model: 'claude-opus-4-6',
max_tokens: 4096,
messages: [{ role: 'user', content: prompt }],
tools
});
let toolUseBlocks: any[] = [];
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
yield event.delta.text;
}
if (event.type === 'content_block_stop' && event.content_block.type === 'tool_use') {
toolUseBlocks.push(event.content_block);
}
}
return toolUseBlocks;
}Structured Output (JSON Mode, Tool Use)
BAD: String parsing, fragile extraction
async function extractData(text: string) {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{
role: 'user',
content: `Extract name and email from: ${text}. Return as JSON.`
}]
});
const content = response.choices[0].message.content;
return JSON.parse(content.match(/\{.*\}/s)[0]); // Fragile
}GOOD: OpenAI JSON mode with schema validation
import { z } from 'zod';
const ContactSchema = z.object({
name: z.string(),
email: z.string().email(),
phone: z.string().optional()
});
type Contact = z.infer<typeof ContactSchema>;
async function extractContactOpenAI(text: string): Promise<Contact> {
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'system',
content: 'Extract contact information. Respond only with valid JSON matching the schema.'
},
{ role: 'user', content: text }
],
response_format: { type: 'json_object' }
});
const parsed = JSON.parse(response.choices[0].message.content);
return ContactSchema.parse(parsed);
}GOOD: Anthropic tool use for structured output
async function extractContactAnthropic(text: string): Promise<Contact> {
const response = await anthropic.messages.create({
model: 'claude-opus-4-6',
max_tokens: 1024,
tools: [{
name: 'record_contact',
description: 'Record extracted contact information',
input_schema: {
type: 'object',
properties: {
name: { type: 'string', description: 'Full name' },
email: { type: 'string', description: 'Email address' },
phone: { type: 'string', description: 'Phone number' }
},
required: ['name', 'email']
}
}],
messages: [{ role: 'user', content: `Extract contact info: ${text}` }]
});
const toolUse = response.content.find(block => block.type === 'tool_use');
if (!toolUse || toolUse.type !== 'tool_use') {
throw new Error('No tool use in response');
}
return ContactSchema.parse(toolUse.input);
}<!-- See references/advanced.md for extended examples -->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.

