Introducing Miniloop Agents: AI agents that connect to your appsRead more
Emmett Miller
Emmett Miller, Co-Founder

How to Auto-Publish AI-Written Blog Posts to Sanity CMS

April 2, 2026
Share:
How to Auto-Publish AI-Written Blog Posts to Sanity CMS

Publishing blog content consistently is one of those things that sounds simple until you're actually doing it. Between research, drafting, editing, and getting it into your CMS, a single post can eat up half a day. The Miniloop AI Blog Writer template cuts that down to minutes.

This guide walks you through exactly how to set it up and start publishing AI-written drafts directly to your Sanity project.

What the Template Does

The AI Blog Writer is a five-step automated workflow. When you give it a topic, it:

  1. Researches the subject and builds an outline
  2. Writes the full blog post based on that outline
  3. Generates a cover image to go with it
  4. Creates a draft document in your Sanity project
  5. Publishes the document when you're ready

Nothing goes live without your review. Every post lands in Sanity Studio as a draft first, so your team can edit, approve, or reject it before it hits your site.

Step 1: Clone the Template

Go to miniloop.ai/c/templates/blog-poster/setup and click Clone Template.

This creates a private copy of the agent in your Miniloop dashboard. The agent is yours to configure, run, and modify.

Step 2: Connect Your Sanity Project

The template needs to connect to your Sanity project to create and publish documents. You'll need three things:

  • Project ID — found in your Sanity project settings
  • Dataset — usually production
  • API Token — needs write and publish permissions

Finding Your Project ID and Dataset

  1. Go to sanity.io/manage and open your project
  2. Your Project ID is shown at the top of the project overview page
  3. Your datasets are listed under the Datasets tab — copy the name of the one your site uses

Creating an API Token

  1. In your Sanity project, go to Settings and then API
  2. Click Add API token
  3. Give it a name like Miniloop Blog Writer
  4. Set permissions to Editor (this allows creating and publishing documents)
  5. Copy the token — you won't be able to see it again after closing the dialog

Adding the Connection in Miniloop

Inside your cloned agent, open the CMS connection settings and select Sanity. Paste in your Project ID, dataset name, and API token, then click Verify and Connect.

Once connected, you can configure which document type to use for posts and map fields like title, slug, body, and image to your schema.

Want to automate your workflows?

Miniloop connects your apps and runs tasks with AI. No code required.

Try it free

Step 3: What to Say to Your Agent

Once connected, open your agent and give it a topic. Be specific. The more context you give, the better the output.

Here are some example prompts:

  • Write a blog post about the top benefits of headless CMS for marketing teams. Target keyword: headless CMS benefits.
  • Write a 1500-word post comparing Sanity and Contentful for developer teams. Focus on schema flexibility and API access.
  • Create a beginner guide to structured content. Explain what it is, why it matters, and how Sanity uses it.

You can also include tone instructions:

  • Write in a conversational tone, avoid jargon, and keep paragraphs short.
  • This is for a technical audience. Go deep on implementation details.

After you send the prompt, the agent handles the rest. You can watch it work through each step in real time.

Step 4: Review in Sanity Studio

When the agent finishes, your post appears as a draft in Sanity Studio. Open it and give it a read.

The AI does a solid first draft, but you'll want to:

  • Add any proprietary data, customer examples, or internal insights the AI doesn't have access to
  • Adjust the intro if it feels generic
  • Check that the keyword placement feels natural
  • Confirm the slug and metadata look right

When you're happy with it, hit Publish in Studio. Or let the agent publish it directly if you've set that up.

Tips for Better Output

Give it a real angle. Instead of write about content marketing, try write about why most content marketing fails and what to do instead. A specific angle produces a more useful post.

Use brand voice guidelines. If your team has a style guide, paste key points into your agent settings. Things like preferred tone, words to avoid, and formatting preferences.

Review before publishing. The agent creates drafts. Treat them like you would a draft from a junior writer. Good foundation, needs a human pass.

Frequently Asked Questions

Do I need an OpenAI account to use this template? No. The AI capabilities are built into the Miniloop platform. You only need to connect your Sanity project.

Does this work with any Sanity schema? Yes. During setup, you map the agent's output to your specific field names. Common fields like title, slug, body, and image work out of the box. Custom fields can be mapped or given defaults.

Will posts go live automatically? Not by default. Every post is created as a draft in Sanity Studio. Your team reviews and publishes manually. You can configure the agent to publish automatically if you prefer.

What API token permissions do I need? Your token needs Editor-level permissions so it can create and publish documents. A Viewer or Read-only token won't work.

Can I run this on a schedule? Yes. Inside Miniloop, you can schedule the agent to run automatically on a cadence that fits your publishing calendar.

What if my schema uses custom block types? The agent creates standard Portable Text output by default. If your schema uses custom block types like callouts or code blocks, you can extend the configuration to support them.

Frequently Asked Questions

Do I need an OpenAI account to use this template?

No. The AI capabilities are built into the Miniloop platform. You only need to connect your Sanity project with your Project ID, dataset, and API token.

Does this work with any Sanity schema?

Yes. During setup you map the agent's output to your specific field names. Common fields like title, slug, body, and image work out of the box. Custom fields can be mapped or given defaults.

Will posts go live automatically?

Not by default. Every post is created as a draft in Sanity Studio. Your team reviews and publishes manually, though you can configure the agent to publish automatically.

What API token permissions do I need?

Your Sanity API token needs Editor-level permissions so it can create and publish documents. A Viewer or Read-only token will not work.

Can I run this on a schedule?

Yes. Inside Miniloop you can schedule the agent to run automatically on a cadence that fits your publishing calendar.

What if my schema uses custom block types?

The agent creates standard Portable Text output by default. If your schema uses custom block types like callouts or code blocks, you can extend the configuration to support them.

Related Templates

Automate workflows related to this topic with ready-to-use templates.

View all templates
OpenAISanity

AI Blog Writer for Sanity CMS

Publish AI-written blog posts with cover images directly to Sanity. From topic to published draft in minutes, not hours.

OpenAIWordPress

AI Blog Writer for WordPress

Publish AI-written blog posts with featured images directly to WordPress. From topic to draft in minutes. Works with any theme.

OpenAIContentful

AI Blog Writer for Contentful

Publish AI-written blog posts with cover images to Contentful. Structured content that works across web, mobile, and any channel.

Related Articles

Explore more insights and guides on automation and AI.

View all articles