Affinity Design
Agency Guide

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:

BucketPurposeModel TierGemini Model
AwarenessTop-of-funnel, educational, entertainingFlashgemini-3-flash-preview
TrustSocial proof, case studies, testimonialsFlashgemini-3-flash-preview
CTAConversion-focused, direct offersProgemini-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:

  • awarenessflashgemini-3-flash-preview
  • trustflashgemini-3-flash-preview
  • ctaprogemini-3-pro-preview

Text Generation Models

EndpointModelTierPurpose
Brand voice extractiongemini-3-pro-previewProDeep analysis of content samples
Generate post (CTA bucket)gemini-3-pro-previewProHigh-quality conversion copy
Generate post (awareness/trust)gemini-3-flash-previewFlashFast, cost-effective content
Suggest anglesgemini-3-flash-previewFlashQuick angle ideation (3 per request)
Extract design configgemini-3-flash-previewFlashVisual brand extraction from URL
Caption generationgemini-3-flash-previewFlashStandalone caption helper
Hashtag generationgemini-3-flash-previewFlashTag 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 CaseModel
REST text/structured outputgemini-3-flash-preview
REST complex reasoninggemini-3-pro-preview
REST image gengemini-3-pro-image-preview
Live API (voice)gemini-3.1-flash-live-preview
Pipeline text LLMgemini-3.1-flash-lite-preview

Image Generation

EndpointModelProviderGateway
Post image generationgpt-image-2Replicate or OpenAI ImagesYes (CF AI Gateway)

Implementation in utils/gemini-image.js:

  • Default path: openai/gpt-image-2 on Replicate when Cloudflare AI Gateway or REPLICATE_API_TOKEN is configured
  • Fallback path: OpenAI's Images API directly with gpt-image-2 when only OPENAI_API_KEY is available
  • Both paths support first-party asset storage and auto-upload to GHL media library
  • Decodes GPT image b64_json response format

Requests requiring transparent backgrounds fall back to openai/gpt-image-1.5 because gpt-image-2 does not support transparent backgrounds on Replicate.

Manual compose carousel prompts (e.g. "7-slide Instagram carousel") are inferred as multiple images:

  • Each frame is generated and returned as mediaUrls
  • mediaUrl is 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.

On this page