agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when integrating an LLM API into an application. Covers streaming, retries and rate limits, timeouts, caching, fallback across providers, and the production concerns that a tutorial integration ignores. Trigger on "add an llm to our app", "getting 429 rate limit errors from
Claude Code
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill llm-integration --agent claude-code
Codex
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a codex -y
Cursor
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a cursor -y
Gemini CLI
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a gemini-cli -y
GitHub Copilot
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a github-copilot -y
OpenCode
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a opencode -y
Windsurf
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-integration -a windsurf -y
name: llm-integration description: Use when integrating an LLM API into an application. Covers streaming, retries and rate limits, timeouts, caching, fallback across providers, and the production concerns that a tutorial integration ignores. Trigger on "add an llm to our app", "getting 429 rate limit errors from the api", "stream the response to the frontend". Do not use for reducing token spend — see the llm-cost-optimization skill; for parsing JSON from the model, see the structured-output skill. metadata: category: ai version: 1.0.0 tags: [llm, api, streaming, retries, production]
Integrate a language model into a production application, where the API is slow, rate-limited, occasionally down, and billed per token — none of which the quickstart mentions.
1. **Stream anything a human waits for** — A 12-second response that starts rendering at 400ms feels fast. The same response delivered at once feels broken. Streaming is a perceived-latency fix, not a throughput one. 2. **Handle rate limits properly** — Honor `Retry-After`. Exponential backoff with jitter. A retry storm against a rate-limited endpoint extends the outage. 3. **Set a timeout** — LLM calls can hang. An unbounded call holds a connection and a worker until something else breaks. 4. **Cache the stable prefix** — Prompt caching makes a large system prompt nearly free after the first call. This is often the largest single cost reduction available. 5. **Fail over deliberately** — A second provider or a smaller model as a fallback. Decide in advance whether a degraded answer is better than no answer for this feature. 6. **Instrument tokens and cost per call** — Attributed to the feature and the tenant. Without this, an LLM bill is an unexplainable number.
**A production client: timeout, retry, cache, fallback:**
class LLMClient:
def __init__(self, primary: Provider, fallback: Provider | None = None):
self.primary = primary
self.fallback = fallback
self.breaker = CircuitBreaker(failure_threshold=5, reset_timeout=30)
async def complete(
self,
system: str,
messages: list[Message],
*,
max_tokens: int = 2048,
timeout: float = 60.0,
) -> Completion:
for attempt in range(3):
try:
if self.breaker.is_open:
break # skip straight to the fallback
async with asyncio.timeout(timeout):
result = await self.primary.complete(
system=[{
"type": "text",
"text": system,
"cache_control": {"type": "ephemeral"}, # cache the prefix
}],
messages=messages,
max_tokens=max_tokens,
)
self.breaker.record_success()
metrics.record(
provider="primary",
input_tokens=result.usage.input_tokens,
cached_tokens=result.usage.cache_read_input_tokens,
output_tokens=result.usage.output_tokens,
cost_cents=cost_of(result.usage),
)
return result
except RateLimitError as e:
# Honor the server's instruction. Do not invent your own backoff.
await asyncio.sleep(e.retry_after or (2 ** attempt) + random.random())
except (APIError, TimeoutError) as e:
self.breaker.record_failure()
if attempt == 2:
break
await asyncio.sleep((2 ** attempt) + random.random())
except BadRequestError:
raise # malformed: retrying changes nothing
if self.fallback:
logger.warning("primary_llm_unavailable_using_fallback")
return await self.fallback.complete(system=system, messages=messages,
max_tokens=max_tokens)
raise LLMUnavailable("primary failed and no fallback is configured")**Streaming to the user while accumulating for storage:**
async def stream_answer(q
A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory,…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling,…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.