소스 정보
- 저장소
- tools-only/X-Skills
- 최근 소스 활동
- 2026년 2월 9일 04:32
- 감지된 SKILL.md 언어
- 영어
- 스타
- 7
- 포크
- 1
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/tools-only/X-Skills --skill llm-api-scaffold명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Index of Build Systems Skills
Coordination patterns for distributed dataflow systems including barriers, epochs, and distributed snapshots
Windowing, sessionization, time-series aggregation, and late data handling for streaming systems
SOC 직업 분류 기준
SKILL.md 표시 중
| name | llm-api-scaffold |
| description | Generate production-ready LLM API integration boilerplate |
| shortcut | las |
| category | other |
| type | command |
| version | 1.0.0 |
| author | Jeremy Longshore |
| estimated_time | 5-10 minutes |
Generate complete, production-ready LLM API integration code with error handling, rate limiting, caching, monitoring, and best practices built-in.
When you run this command, you'll receive:
/llm-api-scaffold <provider> [options]
Providers: anthropic, openai, multi (both)
Examples:
/las anthropic - Generate Anthropic Claude integration/las openai - Generate OpenAI GPT integration/las multi - Generate multi-provider with fallbackInput:
/las anthropic
Output:
llm-api-integration/
├── src/
│ ├── client/
│ │ ├── __init__.py
│ │ ├── base.py # Base client interface
│ │ ├── anthropic_client.py # Anthropic implementation
│ │ └── rate_limiter.py # Rate limiting
│ ├── cache/
│ │ ├── __init__.py
│ │ ├── memory_cache.py # In-memory cache
│ │ └── redis_cache.py # Redis cache
│ ├── monitoring/
│ │ ├── __init__.py
│ │ ├── metrics.py # Prometheus metrics
│ │ └── cost_tracker.py # Cost tracking
│ └── utils/
│ ├── __init__.py
│ └── retry.py # Retry logic
├── tests/
│ ├── __init__.py
│ ├── test_client.py
│ └── test_cache.py
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
├── requirements.txt
├── .env.example
└── README.md
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional, AsyncGenerator
@dataclass
class CompletionRequest:
"""Standardized completion request."""
prompt: str
max_tokens: int = 1024
temperature: float = 1.0
model: Optional[str] = None
stream: bool = False
@dataclass
class CompletionResponse:
"""Standardized completion response."""
content: str
usage: dict
model: str
latency: float
cached: bool = False
provider: str = ""
class BaseLLMClient(ABC):
"""Abstract base class for LLM clients."""
@abstractmethod
async def complete(self, request: CompletionRequest) -> CompletionResponse:
"""Generate completion."""
pass
@abstractmethod
async def stream_complete(
self,
request: CompletionRequest
) -> AsyncGenerator[, ]:
() -> :
import time
import asyncio
from anthropic import AsyncAnthropic, RateLimitError, APIError
from .base import BaseLLMClient, CompletionRequest, CompletionResponse
from .rate_limiter import TokenBucket
from ..cache import CacheManager
from ..monitoring import MetricsCollector, CostTracker
from ..utils.retry import retry_with_backoff
class AnthropicClient(BaseLLMClient):
"""Production-ready Anthropic Claude client."""
def __init__(
self,
api_key: str,
model: str = "claude-3-haiku-20240307",
requests_per_minute: int = 50,
enable_cache: bool = True,
enable_metrics: bool = True
):
"""Initialize Anthropic client with production features.
Args:
api_key: Anthropic API key
model: Default model to use
requests_per_minute: Rate limit (adjust based on tier)
enable_cache: Enable response caching
enable_metrics: Enable metrics collection
"""
self.client = AsyncAnthropic(api_key=api_key)
self.model = model
self.rate_limiter = TokenBucket(
capacity=requests_per_minute,
refill_rate=requests_per_minute / 60.0
)
self.cache = CacheManager() if enable_cache else
.metrics = MetricsCollector() enable_metrics
.cost_tracker = CostTracker()
() -> CompletionResponse:
.rate_limiter.wait_for_token()
.cache:
cache_key = ._generate_cache_key(request)
cached = .cache.get(cache_key)
cached:
.metrics .metrics.record_cache_hit()
CompletionResponse(**cached, cached=)
start_time = time.time()
model = request.model .model
:
message = .client.messages.create(
model=model,
max_tokens=request.max_tokens,
temperature=request.temperature,
messages=[{: , : request.prompt}]
)
latency = time.time() - start_time
response = CompletionResponse(
content=message.content[].text,
usage={
: message.usage.input_tokens,
: message.usage.output_tokens
},
model=model,
latency=latency,
provider=
)
.cache:
.cache.(cache_key, response.__dict__, ttl=)
.metrics:
.metrics.record_request(
provider=,
model=model,
latency=latency,
tokens=response.usage[]
)
cost = .cost_tracker.calculate_cost(
input_tokens=response.usage[],
output_tokens=response.usage[],
model=model
)
.cost_tracker.log_request(model, cost)
response
RateLimitError e:
.metrics .metrics.record_error()
APIError e:
.metrics .metrics.record_error()
() -> AsyncGenerator[, ]:
.rate_limiter.wait_for_token()
model = request.model .model
start_time = time.time()
.client.messages.stream(
model=model,
max_tokens=request.max_tokens,
temperature=request.temperature,
messages=[{: , : request.prompt}]
) stream:
text stream.text_stream:
text
message = stream.get_final_message()
latency = time.time() - start_time
.metrics:
.metrics.record_request(
provider=,
model=model,
latency=latency,
tokens=message.usage.output_tokens
)
cost = .cost_tracker.calculate_cost(
input_tokens=message.usage.input_tokens,
output_tokens=message.usage.output_tokens,
model=model
)
.cost_tracker.log_request(model, cost)
() -> :
(text) //
() -> :
hashlib
key_string =
hashlib.md5(key_string.encode()).hexdigest()
() -> :
{
: .cost_tracker.get_stats(),
: .metrics.get_stats() .metrics {}
}
import time
import asyncio
from threading import Lock
class TokenBucket:
"""Thread-safe token bucket for rate limiting."""
def __init__(self, capacity: int, refill_rate: float):
"""
Args:
capacity: Maximum tokens (e.g., 50 requests)
refill_rate: Tokens per second (e.g., 50/60 = 0.833 req/s)
"""
self.capacity = capacity
self.tokens = capacity
self.refill_rate = refill_rate
self.last_refill = time.time()
self.lock = Lock()
def _refill(self):
"""Refill tokens based on elapsed time."""
now = time.time()
elapsed = now - self.last_refill
tokens_to_add = elapsed * self.refill_rate
self.tokens = min(self.capacity, self.tokens + tokens_to_add)
self.last_refill = now
def consume(self, tokens: int = 1) -> bool:
"""Try to consume tokens. Returns True if successful."""
with self.lock:
self._refill()
if self.tokens >= tokens:
.tokens -= tokens
():
.consume(tokens):
asyncio.sleep()
import time
from typing import Optional, Any
from collections import OrderedDict
class MemoryCache:
"""In-memory LRU cache with TTL."""
def __init__(self, max_size: int = 1000):
self.max_size = max_size
self.cache = OrderedDict()
self.expiry = {}
async def get(self, key: str) -> Optional[Any]:
"""Get cached value if not expired."""
if key not in self.cache:
return None
# Check expiry
if key in self.expiry and time.time() > self.expiry[key]:
del self.cache[key]
del self.expiry[key]
return None
# Move to end (LRU)
self.cache.move_to_end(key)
return self.cache[key]
async ():
key .cache:
.cache.move_to_end(key)
:
.cache[key] = value
(.cache) > .max_size:
oldest_key = ((.cache))
.cache[oldest_key]
oldest_key .expiry:
.expiry[oldest_key]
.cache[key] = value
.expiry[key] = time.time() + ttl
():
key .cache:
.cache[key]
key .expiry:
.expiry[key]
():
.cache.clear()
.expiry.clear()
import time
from collections import defaultdict
from dataclasses import dataclass, field
@dataclass
class CostTracker:
"""Track LLM usage costs."""
usage_history: list = field(default_factory=list)
costs_by_model: dict = field(default_factory=lambda: defaultdict(float))
PRICING = {
"claude-3-opus-20240229": {"input": 0.015, "output": 0.075},
"claude-3-sonnet-20240229": {"input": 0.003, "output": 0.015},
"claude-3-haiku-20240307": {"input": 0.00025, "output": 0.00125},
"gpt-4-turbo-preview": {"input": 0.01, "output": 0.03},
"gpt-3.5-turbo": {"input": 0.0005, "output": 0.0015}
}
def calculate_cost(
self,
input_tokens: int,
output_tokens: int,
model: str
) -> float:
"""Calculate cost for request."""
rates = self.PRICING.get(model, .PRICING[])
input_cost = (input_tokens / ) * rates[]
output_cost = (output_tokens / ) * rates[]
input_cost + output_cost
():
.usage_history.append({
: time.time(),
: model,
: cost
})
.costs_by_model[model] += cost
() -> :
.usage_history:
{: , : }
total_cost = (r[] r .usage_history)
{
: (.usage_history),
: total_cost,
: total_cost / (.usage_history),
: (.costs_by_model)
}
import time
import random
import asyncio
from functools import wraps
def retry_with_backoff(
max_retries: int = 3,
base_delay: float = 1.0,
max_delay: float = 60.0,
exponential_base: float = 2.0,
jitter: bool = True
):
"""Async retry decorator with exponential backoff."""
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
retries = 0
while retries < max_retries:
try:
return await func(*args, **kwargs)
except Exception as e:
retries += 1
if retries >= max_retries:
raise
delay = min(base_delay * (exponential_base ** retries), max_delay)
if jitter:
delay = delay * (0.5 + random.random())
print(f"Retry {retries}/{max_retries} after {delay:.2f}s: ")
asyncio.sleep(delay)
func(*args, **kwargs)
wrapper
decorator
import pytest
import asyncio
from src.client.anthropic_client import AnthropicClient, CompletionRequest
@pytest.mark.asyncio
async def test_completion():
"""Test basic completion."""
client = AnthropicClient(api_key="test-key", enable_cache=False)
request = CompletionRequest(
prompt="What is 2+2?",
max_tokens=100
)
response = await client.complete(request)
assert response.content
assert response.usage["output_tokens"] > 0
assert response.latency > 0
assert response.provider == "anthropic"
@pytest.mark.asyncio
async def test_caching():
"""Test response caching."""
client = AnthropicClient(api_key="test-key", enable_cache=True)
request = CompletionRequest(prompt="Test prompt", max_tokens=50)
# First call
response1 = await client.complete(request)
assert not response1.cached
# Second call (should be cached)
response2 = await client.complete(request)
assert response2.cached
assert response2.content == response1.content
@pytest.mark.asyncio
async def test_rate_limiting():
client = AnthropicClient(api_key=, requests_per_minute=)
start = asyncio.get_event_loop().time()
_ ():
client.complete(CompletionRequest(prompt=, max_tokens=))
elapsed = asyncio.get_event_loop().time() - start
elapsed >=
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY src/ ./src/
# Environment variables
ENV ANTHROPIC_API_KEY=""
ENV REDIS_URL="redis://redis:6379"
# Run application
CMD ["python", "-m", "src.main"]
version: '3.8'
services:
app:
build:
context: .
dockerfile: docker/Dockerfile
environment:
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- REDIS_URL=redis://redis:6379
depends_on:
- redis
ports:
- "8000:8000"
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis-data:/data
volumes:
redis-data:
anthropic==0.18.1
redis==5.0.1
prometheus-client==0.19.0
pytest==7.4.3
pytest-asyncio==0.21.1
python-dotenv==1.0.0
import asyncio
from src.client.anthropic_client import AnthropicClient, CompletionRequest
async def main():
# Initialize client
client = AnthropicClient(
api_key="your-api-key",
model="claude-3-haiku-20240307",
requests_per_minute=50,
enable_cache=True,
enable_metrics=True
)
# Simple completion
request = CompletionRequest(
prompt="Explain quantum computing in 3 sentences",
max_tokens=200
)
response = await client.complete(request)
print(f"Response: {response.content}")
print(f"Latency: {response.latency:.2f}s")
print(f"Cached: {response.cached}")
# Streaming completion
print("\nStreaming response:")
async for token in client.stream_complete(request):
print(token, end="", flush=True)
# Get statistics
stats = await client.get_stats()
print(f"\n\nTotal cost: ${stats['cost_tracker']['total_cost']:.4f}")
print(f"Requests: {stats[][]}")
__name__ == :
asyncio.run(main())
Production-Ready:
Cost Optimization:
Reliability:
Manual implementation: 8-12 hours
With this command: 5-10 minutes
ROI: 48-72x time multiplier
Next Steps:
/las anthropic or /las openai or /las multipip install -r requirements.txtexport ANTHROPIC_API_KEY=your-keypython example.pydocker-compose up -dProduction checklist:
Estimated monthly cost: $0.10 - $10+ depending on usage volume.