twofourlabs/agent-docs/ai-integrated-api-backend
- community
Checking that the SKILL.md file is still in the repository.
Comprehensive guide for building production-grade AI-integrated backends with multi-provider support, intelligent fallback mechanisms, region configuration, prompt management with variables/tools, and session-based billing. Use when implementing AI features in Django/Python backends or designing LLM-powered API architectures with external data integration.
Install
npx vskill@latest install twofourlabs/agent-docs/ai-integrated-api-backendSKILL.md
<objective> This skill provides exhaustive knowledge for building robust, production-grade AI-integrated backend systems featuring:
- Multi-Provider Architecture: OpenAI, Anthropic, Gemini, AWS Bedrock, Byteplus, OpenRouter with seamless switching
- Intelligent Fallbacks: Automatic degradation chains (e.g., GPT-4 → Claude → Gemini-Flash)
- Region-Based Routing: AWS Bedrock multi-region support, geographic failover
- Advanced Prompt Management: Template-driven prompts with {{variable}} substitution, function mapping, YAML-structured instructions
- External API Integration: Weather, astrology, finance APIs → AI transformation pipelines
- Session & Billing: Per-message charging, wallet deduction, price locking
- Gateway Pattern: JWT-authenticated internal LLM gateway for centralized AI access
</objective>
<essential_principles>
Core Architecture Principles
1. Multi-Provider Design Philosophy
- Never depend on a single AI provider; always maintain fallback chains
- Design provider-agnostic interfaces that abstract vendor-specific implementations
- Implement graceful degradation when premium models fail (e.g., GPT-4 → GPT-3.5 → Gemini-Flash)
- Use configuration-driven provider selection, not hardcoded logic
- Support multiple providers simultaneously (A/B testing, cost optimization)
2. Separation of Concerns
- Models Layer: Database models for bots, LLM configs, prompts, sessions (Django ORM)
- Services Layer: Provider-specific integrations (OpenAI, Anthropic, Gemini, Bedrock, etc.)
- Helpers Layer: Business logic for prompt rendering, fallback routing, response handling
- Gateway Layer: Central JWT-authenticated service for LLM API access
- API Layer: External API managers for weather, astrology, finance data
3. Configuration Over Code
- Store LLM configurations (provider, model, temperature, tokens) in database
- Enable A/B testing by switching active configurations without code deployments
- Support per-bot customization of AI behavior through metadata fields
- Use
is_activeflag to switch between configurations instantly
4. Prompt Engineering Best Practices
- Template-driven prompts with variable substitution (
{{variable_name}}) - Centralized prompt management separate from business logic
- Support for system-level variables ({{current_date}}, {{current_time}}) and user-level variables ({{user_name}}, {{user_age}})
- YAML-based structured prompts for complex multi-section instructions
- Function mapping for dynamic variable resolution
5. Fallback & Resilience
- Every provider has a fallback chain ending in a reliable universal fallback (e.g., Gemini-Flash)
- Fallbacks inherit system instructions and region configurations
- Support provider-specific fallbacks (e.g., Gemini Pro → Gemini Flash) and cross-provider fallbacks
- Region-aware fallbacks for AWS Bedrock (ap-south-1, us-east-1, etc.)
6. Security & Authentication
- JWT tokens for internal LLM gateway authentication
- Token caching to reduce overhead (cache duration: token expiry - 2 seconds)
- API key management from environment variables
- Service-to-service authentication with signed payloads
</essential_principles>
<system_architecture>
High-Level Data Flow
Full Request Flow (External API → AI → Response)
Multi-Provider Routing with Fallbacks
</system_architecture>
<domain_knowledge_index> All implementation details, code examples, and architectural patterns are organized below:
System Architecture:
- Multi-Provider Architecture (see <multi_provider_architecture>)
- Database Schema for Bots, LLM Configs (see <database_schema>)
- LLM Gateway Pattern with JWT (see <gateway_pattern>)
Provider Integration:
- Provider Implementations (OpenAI, Anthropic, Gemini, Bedrock, Byteplus, OpenRouter)
- Fallback Mechanisms & Retry Logic (see <fallback_mechanisms>)
- Region Configuration for AWS Bedrock (see <region_configuration>)
Prompt Management:
- Prompt Templating System with {{variables}} (see <prompt_templating>)
- Prompt Design Patterns (YAML-structured, role-based) (see <prompt_design_patterns>)
- Dynamic Variables & Function Mapping (see <dynamic_variables>)
External API Integration:
- External API Managers (Astrology, Weather, etc.)
- Data Transformation Pipelines (validate → normalize → enrich → format)
- Multi-Layer Caching Strategy (instance → distributed → database)
Production Considerations:
- JWT Authentication & Security (see <authentication_security>)
- Caching Strategies (token cache, response cache)
- Monitoring & Observability (Langfuse integration)
- Error Handling & Graceful Degradation
Code Examples:
- Complete Working Code Samples (see <implementation_examples>)
</domain_knowledge_index>
<database_schema>
Django Models for AI-Integrated Backend
Bot Model (Core Entity)
Key Design Decisions:
metadataJSONField for flexible per-bot configuration (required_fields, character_rating, pricing)- Soft deletion with
deleted_attimestamp instead of hard delete slugauto-generated from name for SEO-friendly URLsrankfor custom ordering in UI
BotLLMConfig Model (Multi-Provider Configuration)
Key Design Decisions:
- One
Botcan have multipleBotLLMConfigentries for A/B testing is_activeflag controls which config is used (only one active per bot)- Save method enforces single active config constraint
metadatastores provider-specific settings (e.g.,region_namefor AWS Bedrock)
BotLLMProvider Choices
Why This Design:
- Supports multiple providers without code changes
- Easy to add new providers (add to choices, implement integration)
- Database-level validation ensures valid provider names
</database_schema>
<fallback_mechanisms>
Intelligent Fallback Routing
Core Fallback Pattern (from Production Code)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ai-integrated-api-backend/SKILL.md
Popularity
- Repository stars
- 6
- 7-day trend score
- 10
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 24 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/twofourlabs/agent-docs/ai-integrated-api-backend)