Content Brief Generator API Contract
Defines the request and response contract for a serverless function that generates content briefs from client data and research.
What this file does
Defines the request and response contract for a serverless function that generates content briefs from client data and research.
When to use it
- Building a content brief generator with a Supabase backend and edge functions
- Standardising frontend-backend communication for an AI-powered content tool
- Documenting an API contract for a multi-step research and generation pipeline
- Onboarding new developers to the data flow of a content marketing feature
Assumes this stack
Content Brief Generator API Contract
This document defines the API contract between the frontend and the backend edge function for the Content Brief Generator feature.
Edge Function: content-brief-generator
Endpoint
/functions/v1/content-brief-generator
Authentication
- Requires a valid JWT token in the Authorization header
- User must be authenticated and have access to the selected client
Request Format
{
"client_id": "uuid-string",
"title": "Example Working Title",
"keywords": ["keyword1", "keyword2", "keyword3"],
"purpose": "inform | convert | awareness | authority | seo",
"audience": "beginners | intermediate | advanced | decision-makers",
"style_guide": "Optional style requirements and formatting preferences",
"custom_instructions": "Any specific requirements or additional context"
}
Required Fields:
client_id: UUID of the client in the Supabase databasetitle: The working title for the content briefkeywords: Array of 1-5 target keywords
Optional Fields:
purpose: Content purpose (defaults to "inform" if not provided)audience: Target audience (defaults to "intermediate" if not provided)style_guide: Content style guidelinescustom_instructions: Additional specific instructions
Response Format
{
"success": true,
"brief": {
"id": "generated-brief-uuid",
"client_id": "client-uuid",
"title": "Final Recommended Title",
"meta": {
"client_name": "Client Name",
"client_domain": "example.com",
"client_info": {
// Client metadata from database
},
"keywords": ["keyword1", "keyword2"],
"purpose": "inform",
"audience": "intermediate",
"generated_at": "2025-06-17T15:30:00Z",
"research_stats": {
"llm_queries_executed": 3,
"google_searches_performed": 2,
"pages_analyzed": 7,
"competitor_pages_analyzed": 3
}
},
"summary": "Summary of findings from the research process, with emphasis on competitor domains and content approach.",
"content_suggestions": [
{
"suggestion": "Include a comparison table of [topic] features with competitors",
"importance": 9.8,
"rationale": "Competitive analysis shows users appreciate direct feature comparisons"
},
// Additional suggestions (max 5)
],
"table_of_contents": [
{
"title": "Section 1: Introduction to [Topic]",
"points": [
"Provide industry context and relevance",
"Establish key challenges that readers face",
"Present a brief overview of what the article covers"
]
},
// Additional sections (max 7)
],
"research_links": [
{
"title": "Source Title",
"url": "https://example.com/source",
"description": "Contains relevant statistics on industry growth",
"source_type": "research | news | academic | industry"
},
// Additional sources (max 5)
],
"process_notes": {
"llm_responses": [
// Summaries of LLM responses (for transparency)
],
"search_results": [
// Key search results analyzed
],
"competitor_insights": [
// Insights from competitor analysis
]
}
}
}
Error Response
{
"success": false,
"error": {
"code": "error_code",
"message": "Human-readable error message",
"details": {
// Additional error context if available
}
}
}
Common Error Codes
auth_error: Authentication issue (invalid or expired token)permission_error: User doesn't have access to the requested clientclient_not_found: Specified client_id doesn't existinvalid_parameters: Missing or invalid request parametersapi_rate_limit: External API rate limit exceeded (Google, OpenAI, etc.)process_error: Error during brief generation processservice_unavailable: Temporary service unavailability
Processing Steps
-
Request Validation
- Validate authentication and permissions
- Verify client existence and access rights
- Validate required parameters
-
Client Data Retrieval
- Fetch client profile and metadata
- Retrieve competitor information
- Gather existing client content and keywords
-
AI Query Generation
- Analyze inputs to generate LLM research queries
- Create diverse queries covering different angles
-
Research Execution
- Run LLM queries (ChatGPT, Perplexity)
- Execute Google searches for primary and client-specific keywords
- Process and analyze responses
-
Web Content Analysis
- Scrape and extract content from search results
- Analyze competitor content structure and approach
- Identify patterns and opportunities
-
Brief Generation
- Synthesize research into findings summary
- Generate high-importance content suggestions
- Create structured table of contents
- Identify and verify quality research links
-
Response Formatting
- Format all components into the response structure
- Store brief in database for future reference
- Return complete brief data
Implementation Notes
- The edge function should implement appropriate error handling and timeout management
- Authentication should be implemented using Supabase JWT verification
- All external API calls (OpenAI, Google, ScrapingBee) should implement retry logic
- Response data should be cached in Supabase for future reference
- Processing should follow a step-by-step approach with appropriate logging
- Long-running operations should be handled with appropriate timeouts and chunking
What's inside
1 endpoint definition, 2 request/response schemas, 7 processing steps, 7 error codes, implementation notes
Change this for your project
- Replace
kwbts/citebotswith your own repository name - Replace
content-brief-generatorwith your own edge function name - Replace
client_idfield references with your own client identifier schema - Replace
research_statsstructure with your own research metrics
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Separating required from optional fields in the request schema to clarify validation rules
- Including a
process_notesblock for transparency into AI decision-making - Listing common error codes with human-readable messages for easier debugging
Related Documents
C&L Answer OS - User Manual
Documents a Next.js SEO/AEO platform with 12 modules for website audits, content generation, lead prospecting, and client management.
Digital Marketing and Content Strategy - Processes Backlog
Catalogues 23 marketing processes across 7 categories for automation via the babysitter system, with implementation priorities and cross-functional dependencies.
Agent Templates
Provides copy-paste agent templates for 58 specialized agents across 6 departments, including class definitions and directory structures.
Canonry GTM Launch Plan
Defines a launch-oriented GTM plan for a CLI/API-first AEO tool, sequencing features and success metrics around agent-driven content workflows.