api-wrapper-builder
Skill1 starsChanged 5 months agoApache-2.0View on GitHub
Creates a clean Python/TypeScript wrapper around an external AI API (OpenAI, Anthropic, Google AI, etc.). Use when abstracting an AI provider for easier use, testing, or provider switching.
In this repository58 other files it gives its agents.
- agent-chain-designerSkill
- embeddings-builderSkill
- evaluation-harnessSkill
- fine-tuning-preparerSkill
- llm-router-builderSkill
- ml-model-trainerSkill
- model-benchmarkerSkill
- prompt-engineerSkill
- rag-pipeline-builderSkill
- synthetic-data-generatorSkill
- vector-db-integratorSkill
- csv-processorSkill
- database-schema-designerSkill
- data-pipeline-builderSkill
- etl-workflow-designerSkill
- json-transformerSkill
- pandas-data-cleanerSkill
- report-generatorSkill
- sql-query-optimizerSkill
- time-series-analyzerSkill
- visualization-generatorSkill
- backup-strategySkill
- ci-cd-optimizerSkill
- docker-compose-generatorSkill
- github-actions-pipelineSkill
- kubernetes-deploymentSkill
- load-balancer-configSkill
- log-aggregator-setupSkill
- monitoring-dashboardSkill
- nginx-config-generatorSkill
- security-hardeningSkill
- ssl-certificate-managerSkill
- terraform-module-builderSkill
- api-security-auditorSkill
- compliance-checkerSkill
- dependency-checkerSkill
- incident-responderSkill
- jwt-security-auditorSkill
- owasp-checkerSkill
- penetration-test-plannerSkill
- secret-detectorSkill
- threat-model-designerSkill
- vulnerability-scannerSkill
- accessibility-auditorSkill
- api-route-builderSkill
- auth-flow-builderSkill
- css-animation-crafterSkill
- form-validatorSkill
- graphql-schema-designerSkill
- html-component-builderSkill
- nextjs-app-scaffoldSkill
- performance-auditorSkill
- pwa-setupSkill
- react-component-generatorSkill
- responsive-layout-systemSkill
- seo-optimizerSkill
- tailwind-design-systemSkill
- websocket-integrationSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
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
- Distinctive: line 60
Use LiteLLM as a base (strongly recommended for most cases) or build a thin adapter layer.
- Distinctive: line 78
Partial failures in streaming: Ensure the caller can still get whatever was generated.
- Distinctive: line 79
Provider-specific quirks: Document them and normalize in the wrapper.
- Distinctive: line 88
All calls are logged with token usage and approximate cost.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Overview
Creates a clean, production-grade client wrapper around one or more AI provider APIs. Covers client class design, retry + exponential backoff with jitter, streaming support, token counting, response parsing/normalization, error classification (rate limit, auth, server, timeout), provider-swappable interface, logging/cost tracking, and a complete, testable implementation (Python example with OpenAI + Anthropic, plus TypeScript notes).
When to Use This Skill
- You are using (or plan to use) one or more LLM APIs and want a consistent interface.
- You need robust error handling, retries, and observability around API calls.
- You want to make it easy to switch providers or add new ones later (multi-LLM strategy).
- Building internal SDKs or agent frameworks that call LLMs.
Prerequisites
- API keys for the provider(s) you will wrap.
- Understanding of the provider's SDK and response shapes.
- (Recommended)
tenacityorbackofffor retries in Python; equivalent in TS.
Steps
- Design the interface (provider-agnostic where possible):
complete(prompt, model, temperature, max_tokens, **kwargs) -> Responsestream(...) -> Iterator[Chunk]count_tokens(text, model) -> int- Common response shape:
text,usage(input/output tokens),model,finish_reason,raw(original response).
- Error classification & handling:
- RateLimitError → retry with backoff, respect
retry-afterwhen present. - AuthenticationError → fail fast, do not retry.
- ServerError / Timeout → retry with jitter.
- ContextLengthExceeded → surface clearly to caller (or auto-truncate with warning).
- RateLimitError → retry with backoff, respect
- Retry strategy:
- Exponential backoff + full jitter.
- Max attempts (e.g., 5).
- Distinguish transient vs permanent errors.
- Streaming:
- Yield chunks as they arrive.
- Accumulate full text for the final response object when needed.
- Handle partial JSON or tool calls correctly.
- Observability:
- Log every request (sanitized) with latency, tokens, cost estimate, error.
- Emit metrics (Prometheus, Datadog, etc.).
- Optional: send traces to LangSmith / Helicone / Phoenix.
- Multi-provider:
- Use LiteLLM as a base (strongly recommended for most cases) or build a thin adapter layer.
- Config-driven model routing.
- Output:
- Complete
LLMClientclass (Python) with the methods above. - Concrete implementations for OpenAI and Anthropic (or LiteLLM wrapper).
- Retry decorator / context manager.
- Token counter (tiktoken for OpenAI, anthropic tokenizer, or approximate).
- Example usage + tests (pytest or vitest).
- Cost calculator.
- Complete
Examples
A full LLMClient that supports both OpenAI and Anthropic (via LiteLLM or direct), with robust retries, streaming, token counting, cost logging, and a clean Response dataclass is included, plus a minimal TypeScript equivalent.
Edge Cases & Error Handling
- Very long prompts: Pre-check token count and raise a clear
ContextLengthErrorbefore calling the API. - Partial failures in streaming: Ensure the caller can still get whatever was generated.
- Provider-specific quirks: Document them and normalize in the wrapper.
Verification
- The wrapper can complete a simple prompt with both providers.
- Streaming works and the final accumulated text matches the non-streaming result.
- Token counting is accurate (or close) for the supported models.
- Rate limit simulation triggers retries and eventually succeeds or fails gracefully.
- Auth error fails immediately without retries.
- All calls are logged with token usage and approximate cost.
- Success: Calling code is much simpler and more robust than using the raw SDKs directly, and switching providers is a config change.
References
- OpenAI Python SDK
- Anthropic Python SDK
- LiteLLM (highly recommended base)
- Tenacity (retry library)
- tiktoken
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.

