Social Media Agent
Automated social media content creation with brand voice extraction, multi-bucket posting, and AI image generation
Overview
The Social Media Agent automates content creation and scheduling across social platforms. It extracts brand voice from existing content, generates posts across three content buckets, creates AI-generated images, and uploads assets to GoHighLevel's media library.
All AI calls route through Cloudflare AI Gateway for caching, rate limiting, observability, and centralized key management.
Setup
Environment Variables
CF_AI_GATEWAY_ACCOUNT_ID=your_account_id
CF_AI_GATEWAY_SLUG=your_gateway_slug
CF_AI_GATEWAY_TOKEN=your_gateway_token
# Image generation (at least one provider required)
IMAGE_GENERATION_PROVIDER=auto # auto|replicate|openai
OPENAI_IMAGE_MODEL=gpt-image-2
REPLICATE_IMAGE_MODEL=openai/gpt-image-2
REPLICATE_API_TOKEN=your_replicate_token
OPENAI_API_KEY=your_openai_key
Cloudflare AI Gateway
Configure all providers in the Cloudflare AI Gateway dashboard (BYOK):
- Google AI Studio — Gemini models
- Replicate — Image generation (gpt-image-1.5)
- OpenAI — Direct Images API fallback and text/STT fallback
- Groq — Available for pipeline STT/LLM
- Grok — Available
Helper utilities in utils/ai-gateway.js: getGeminiRestBaseUrl(), getReplicateBaseUrl(), buildGatewayAuthHeaders(), buildGatewayMetadataHeaders().
Brand Voice Extraction
Brand voice extraction uses Gemini 3 Pro for deep analysis of content samples to produce a full brand voice document. This document then guides all subsequent post generation to maintain consistency across buckets and platforms.
The extract design config endpoint also uses Flash-tier to extract visual brand identity from a website URL — colors, typography, and style preferences that inform image generation.
Content Buckets
Posts are organized into three buckets, each with automatic model routing:
| Bucket | Purpose | Model Tier | Gemini Model |
|---|---|---|---|
| Awareness | Top-of-funnel, educational, entertaining | Flash | gemini-3-flash-preview |
| Trust | Social proof, case studies, testimonials | Flash | gemini-3-flash-preview |
| CTA | Conversion-focused, direct offers | Pro | gemini-3-pro-preview |
Content bucket determines model tier automatically. CTA posts use Pro-tier for higher-quality conversion copy; awareness and trust posts use Flash-tier for fast, cost-effective content.
Tier Strategy
The routing logic lives in utils/social-generate.js:
- awareness →
flash→gemini-3-flash-preview - trust →
flash→gemini-3-flash-preview - cta →
pro→gemini-3-pro-preview
Text Generation Models
| Endpoint | Model | Tier | Purpose |
|---|---|---|---|
| Brand voice extraction | gemini-3-pro-preview | Pro | Deep analysis of content samples |
| Generate post (CTA bucket) | gemini-3-pro-preview | Pro | High-quality conversion copy |
| Generate post (awareness/trust) | gemini-3-flash-preview | Flash | Fast, cost-effective content |
| Suggest angles | gemini-3-flash-preview | Flash | Quick angle ideation (3 per request) |
| Extract design config | gemini-3-flash-preview | Flash | Visual brand extraction from URL |
| Caption generation | gemini-3-flash-preview | Flash | Standalone caption helper |
| Hashtag generation | gemini-3-flash-preview | Flash | Tag suggestions for a given topic |
The table above reflects the default Gemini configuration. The text-generation provider for this agent can be switched per agency to OpenAI, Claude (Anthropic), or GLM (z.ai) at Admin → Config → LLMS — this is a text-only pipeline (no vision calls), so all four providers are supported. Leave it on the default unless you have a specific reason to change it.
Quick Model Reference
| Use Case | Model |
|---|---|
| REST text/structured output | gemini-3-flash-preview |
| REST complex reasoning | gemini-3-pro-preview |
| REST image gen | gemini-3-pro-image-preview |
| Live API (voice) | gemini-3.1-flash-live-preview |
| Pipeline text LLM | gemini-3.1-flash-lite-preview |
Image Generation
| Endpoint | Model | Provider | Gateway |
|---|---|---|---|
| Post image generation | gpt-image-2 | Replicate or OpenAI Images | Yes (CF AI Gateway) |
Implementation in utils/gemini-image.js:
- Default path:
openai/gpt-image-2on Replicate when Cloudflare AI Gateway orREPLICATE_API_TOKENis configured - Fallback path: OpenAI's Images API directly with
gpt-image-2when onlyOPENAI_API_KEYis available - Both paths support first-party asset storage and auto-upload to GHL media library
- Decodes GPT image
b64_jsonresponse format
Requests requiring transparent backgrounds fall back to openai/gpt-image-1.5 because gpt-image-2 does not support transparent backgrounds on Replicate.
Carousel Support
Manual compose carousel prompts (e.g. "7-slide Instagram carousel") are inferred as multiple images:
- Each frame is generated and returned as
mediaUrls mediaUrlis populated with the first frame for backward compatibility- Multi-image generation handles carousel frame sets automatically
Post Scheduling & GHL Media Library
Generated content and images are uploaded to the GoHighLevel media library for scheduling. The agent handles:
- Post copy and caption generation
- Image creation and upload
- Hashtag suggestions
- Scheduling across connected social accounts
All media assets are stored in GHL's first-party asset system, enabling direct scheduling without manual file transfers.
Platform Connection Gate
The agent cross-checks a client's configured target platforms against what's actually connected in GHL before generating anything. A lapsed OAuth token (Meta/Instagram expire fastest) can silently drop a platform from the GHL Social Planner — without this gate the agent would still generate a post that could never publish, indistinguishable from a real dead draft.
If a configured platform isn't connected, or its GHL status is Expired, the agent skips it for that cycle and logs a warn-level event in the agent's Logs tab naming the skipped platform(s), so you know to reconnect it under Social Accounts. The gate fails open: a transient GHL lookup error doesn't halt posting to every other platform, only disables the check for that cycle.
