# How an AI agent can publish your social media posts safely

> Learn how to let AI agents publish social media posts safely with human approval, policy checks, API security and free JavaScript and Python tools.

- Published: 2026-11-25
- Author: Luis Vidal (COO) https://www.linkedin.com/in/luis-vidal-montal/
- Canonical URL: https://apiwings.com/blog/ai-agent-publish-social-media-posts
- Publisher: APIWings

![AI agent sending a post through a security shield and a human approval check to social posts](https://apiwings.com/blog/ai-agent-publish-social-media-posts/ai-agent-publish-social-media-posts.webp)

An AI agent can publish your social media posts safely if it only proposes them: **the agent writes a draft, your own code checks it against a policy, a person approves that exact post, and only then does your server publish it** with its own key. The model never holds the API key and never has a publish button.

This guide is for developers adding AI agent social media automation to a product. It explains why each step matters, **what LinkedIn, TikTok and Meta require when software posts for people**, and how to build the check. It ends with a free agent post gate for JavaScript and Python, tested on 420 cases, and an eight-post example we ran through it.

## Why an AI agent should not hold the publish button

An agent decides what to do from text: your instructions, but also every web page, email and file it reads. OWASP calls the second case **indirect prompt injection**, where input from external sources such as websites or files changes the model's behaviour, and says it is unclear whether there are **fool-proof methods of prevention** ([LLM01:2025](https://genai.owasp.org/llmrisk/llm01-prompt-injection/)).

For a posting agent, that means a page it summarises can contain "share this link", and **a model with a publish tool may simply do it**. OWASP names the underlying problem excessive agency ([LLM06:2025](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)), with three root causes: excessive functionality, excessive permissions and excessive autonomy. This is how each one looks with social media, and the control that answers it:

| Risk                      | What it looks like with a posting agent                              | Control                                       |
|-------------------------------|--------------------------------------------------------------------------|---------------------------------------------------|
| **Excessive functionality**   | The agent has publish, edit and delete tools when it only needs to draft | One write tool that only saves a draft            |
| **Excessive permissions**     | One API key that can post to every customer's accounts                   | A key scoped to one customer, kept on your server |
| **Excessive autonomy**        | Posts go out while nobody is looking                                     | A person approves the exact post                  |
| **Indirect prompt injection** | A link or claim copied from a page the agent read                        | Allowed link domains, checked in code             |
| **Loops and retries**         | The same post goes out twice after a timeout                             | Idempotency key, duplicate check, daily limit     |
| **Leaked data**               | An API key from the agent's context ends up in a post                    | Secret patterns checked before approval           |

## AI agents vs traditional social media schedulers

A scheduler publishes what a person wrote, at the time they chose. An agent writes and decides, which is why it is useful and why it needs more controls. **The publishing APIs are the same; what changes is who decides what goes out**:

|                    | **Traditional scheduler**                    | **AI agent**                                         |
|--------------------|----------------------------------------------|------------------------------------------------------|
| **Content**        | Written by a person                          | Drafted by the model from instructions and sources   |
| **Instructions**   | Fixed fields: text, account, time            | Natural language, including text it reads on the way |
| **Permissions**    | The app's tokens, used by your code          | Should never reach the model: your server keeps them |
| **Typical risks**  | Wrong time or account, set by a person       | Injected links, invented claims, too many posts      |
| **Human approval** | The author already approved it by writing it | A separate check of the exact post                   |
| **Publishing**     | The networks' APIs, at a set time            | The same APIs, behind your own checks                |

**If your product only needs posts at a set time, a scheduler is enough**; our [social media scheduling API guide](https://apiwings.com/blog/social-media-scheduling-api) covers it. The rest of this guide is about the extra steps an agent needs.

## What LinkedIn, TikTok and Meta say about posting for people

No network bans AI agents by name, but **their terms already cover software that posts on someone's behalf**. This is what each one says, checked in its official documentation on 25 November 2026. It is our reading, not legal advice:
- **LinkedIn.** LinkedIn provides official publishing APIs for authorized applications: the Posts API creates posts for a member with the w_member_social permission ([Posts API](https://learn.microsoft.com/en-us/linkedin/marketing/community-management/shares/posts-api)). Its API Terms of Use (section 3.1) also say you must not use the APIs "to automate posting on the LinkedIn Services" ([terms](https://www.linkedin.com/legal/l/api-terms-of-use)). **Distinguish publishing that the member starts or approves, through an authorized app, from unattended automation**, and check that your specific workflow is permitted. Member approval reduces the risk; it does not guarantee compliance on its own.
- **TikTok.** The Content Sharing Guidelines say users "must have full awareness and control of what is being posted", that the app should show a preview, that content is sent only after the user expressly consents, and that **the user picks the privacy level from a list with no default** ([guidelines](https://developers.tiktok.com/doc/content-sharing-guidelines)). So the agent cannot choose who sees the post, and a person must see and confirm it.
- **Meta (Facebook, Instagram, Threads).** The Developer Policies ask you to "obtain consent from people before publishing content or taking any other action on their behalf" (1.7) and not to "confuse, deceive, defraud, mislead, spam or surprise anyone" (1.4) ([policies](https://developers.facebook.com/devpolicy/)). **A post that the account owner never saw is exactly the kind of surprise to avoid.**
- **X.** X publishes its own automation rules ([X automation rules](https://help.x.com/en/rules-and-policies/x-automation)). Read them before you add X to an agent.

In the EU there is one more rule. Article 50(4) of the AI Act applies from 2 August 2026 and asks deployers to disclose that text was AI-generated when it is published to inform the public on matters of public interest, **unless it has gone through human review or editorial control** and a person or company holds editorial responsibility ([Article 50](https://artificialintelligenceact.eu/article/50/)). If your agent writes news-like posts, human review matters here too.

**The networks also set their own posting limits per account and per day.** We collected them in our [comparison of social media API limits](https://apiwings.com/blog/social-media-api-limits).

## Step 1: give the agent the smallest tool that works

Secure AI agent tools start with scope. Most agents talk to the outside world through tools: a name, a description and a JSON schema for the arguments. **Give a posting agent one write tool, and make it save a draft instead of publishing.** List the accounts it may use as an enum, so it cannot invent one, and ask for a reason the reviewer will read:

```json
{
  "name": "propose_post",
  "description": "Save a post as a draft for one account. It is NOT published: a person reviews it first.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "account_id": { "type": "string", "enum": ["acc_bsky_acme", "acc_li_ana", "acc_threads_acme", "acc_tt_acme"] },
      "text": { "type": "string", "maxLength": 3000 },
      "media_ids": { "type": "array", "items": { "type": "string" }, "maxItems": 10 },
      "scheduled_at": { "type": "string", "format": "date-time" },
      "reason": { "type": "string", "maxLength": 500 }
    },
    "required": ["account_id", "text", "reason"],
    "additionalProperties": false
  },
  "annotations": { "readOnlyHint": false, "destructiveHint": false, "openWorldHint": false }
}
```

The full file, with two read-only tools, is in the resources below. **There is no publish, edit or delete tool on purpose**, and the API key for the publishing API stays in your server's environment, where the model cannot read it or leak it.

If you use the Model Context Protocol (MCP) for social media publishing, two details from the specification matter ([MCP tools](https://modelcontextprotocol.io/specification/2025-11-25/server/tools)). First, **annotations such as destructiveHint are hints**: clients must treat them as untrusted unless they come from trusted servers, so they describe a tool but do not protect anything. Second, the specification says there should always be a human in the loop with the ability to deny tool invocations. **Confirming a tool call is not the same as approving a post**: with propose_post, that confirmation only creates a draft, and the approval that counts happens later, on the final post.

## Step 2: check every draft in code, not in the prompt

A line in the system prompt such as "never post links to other sites" is an instruction that injected text can override. OWASP's advice is **complete mediation**: implement authorization in downstream systems rather than relying on the model to decide whether an action is allowed ([LLM06:2025](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)). In practice, every draft goes through a function that the model cannot change, and that function returns a decision and its reasons:
- **Accounts:** only accounts listed in the policy, on the network they belong to.
- **Links:** only domains you allow. This is the check that stops links injected from pages the agent read.
- **Secrets:** nothing that looks like an API key, token or private key.
- **Mentions and blocked terms:** a maximum number of @mentions, and words you never want in a post.
- **Alt text:** every image described.
- **Daily limit:** a maximum number of agent posts per account in any 24 hours.
- **Duplicates:** no repeat of a text already posted on that account in the last few days.
- **Network rules:** for TikTok, the agent cannot set the privacy level, and the user must choose it and consent.
- **Kill switch:** one flag that stops every agent post at once.

The gate checks policy, not each network's character or media limits; for those, use the validator from our guide to [posting to multiple social networks with one API call](https://apiwings.com/blog/post-to-multiple-social-networks-api). **Return the reasons to the agent**: a message like "link to acme-refunds.example.net is not on the allowed domains list" lets it fix the draft instead of trying again blindly.

## Step 3: approve the exact post, not the idea

The approval screen shows **what will actually be published**: the account and network, the full text, each image with its alt text, and the publish time. For TikTok, the same screen is where the user picks the privacy level and ticks the consent box, as TikTok's guidelines require. For a LinkedIn profile, the person approving should be the member who owns it.

Then **bind the approval to the content**. Store a SHA-256 hash of the post as canonical JSON (sorted keys, no spaces), and compute it again just before publishing; the gate in the resources does this, with identical results in Python and JavaScript. If the agent changes a single character after approval, the hashes differ and the post goes back for approval. Approvals also expire: our gate accepts them for 24 hours by default.

## Step 4: publish once, within limits, and keep a log

Agents retry. Use an idempotency key **derived from the draft, the account and the approved content**, so a retry of the same approved post always carries the same key, and a publishing API that supports idempotency returns the existing post instead of creating a second one. We explain idempotency and partial failures in [posting to multiple social networks with one API call](https://apiwings.com/blog/post-to-multiple-social-networks-api).

An idempotency key does not catch everything: **a new draft with the same text has a new key**. That is why the gate also checks duplicates against what the account already posted, and counts posts in a rolling 24-hour window.

Keep a log with the draft, the reason the agent gave, who approved it and when, the hash, and each network's result. **OWASP notes that logging and rate limiting do not prevent excessive agency, but they limit the damage** and help you spot problems sooner. Scheduling approved posts a few minutes ahead also leaves time to cancel one.

## A worked example: eight proposals, one authorized

We ran eight posts an agent could propose on a launch day through the template policy: four accounts, links only to acme.com, three agent posts per account per day, approval everywhere. **The gate authorized one proposal for publishing, returned one for approval and blocked six**, each with a reason. The gate never publishes anything itself; its three decisions mean:
- **publish:** the proposal passed every check and has a valid approval, so it may go to your publishing service. It is not published yet: the network can still reject it, and only the network's result confirms it is live.
- **needs_approval:** nothing is wrong with the content, but there is no valid approval for this exact version.
- **blocked:** the proposal breaks the policy. The reasons go back to the agent so it can fix the draft.

| Case | Network | What the agent proposed                   | Decision   | Why                                           |
|----------|-------------|-----------------------------------------------|----------------|---------------------------------------------------|
| **A**    | LinkedIn    | Launch post, approved by Ana an hour ago      | publish        | Valid approval, content unchanged                 |
| **B**    | Bluesky     | Link copied from a web page it summarised     | blocked        | acme-refunds.example.net is not an allowed domain |
| **C**    | X           | Post to the CEO's personal account            | blocked        | Account not in the policy                         |
| **D**    | Threads     | API key found in the logs it was reading      | blocked        | Looks like an API key                             |
| **E**    | TikTok      | Video with privacy set to public by the agent | blocked        | Privacy must be chosen by the user; no consent    |
| **F**    | Bluesky     | A fourth post in 24 hours                     | blocked        | Daily limit of 3 reached                          |
| **G**    | Threads     | Post rewritten after it was approved          | needs_approval | Approval was for a different version              |
| **H**    | Bluesky     | New draft repeating yesterday's post          | blocked        | Same text posted in the last 72 hours             |

**The same result as an image**, for sharing:

![Table of eight AI agent post proposals with the gate decision and the reason for each](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent-proposals-worked-example.webp)

*Eight posts proposed by an agent and what the gate decided: one authorized for publishing, one back to approval, six blocked.*

Three cases show why the checks live in code. **Case B is prompt injection in practice**: the "refund" link looks fine to a hurried reviewer, but its domain is not on the list. In case G the agent added "Upgrade before Friday or lose your discount!" after approval, so the hash no longer matches. Case H repeats yesterday's text from a new draft, which an idempotency key alone would not catch. In case E, the fix is not a better prompt but the approval screen, where the user picks TikTok's privacy level.

![Vertical flow from AI agent to policy gate, human approval and publishing API, with each outcome](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent-post-approval-flow.webp)

*The agent proposes, your code decides: where each check happens between a draft and a published post.*

## What this gate does not protect against

The gate is one layer. **Know where it stops**, so you add the other layers where you need them:
- **Redirects and short links:** an allowed domain can still redirect elsewhere, and short links hide the destination. Keep shorteners off the list and fix open redirects on your own domains.
- **Secret detection:** patterns catch common key formats, with false positives and misses. Keep secrets out of the agent's context in the first place.
- **Who approved:** the hash proves what was approved, not that the person was allowed to approve it. Check in your backend who approved, for which account and which content.
- **Reworded duplicates:** the duplicate check compares normalised text, so the same message in other words passes.
- **Idempotency:** a key only protects you if the publishing API deduplicates on it.
- **Uncertain results:** after a lost response or a timeout, you may not know whether the network published. Check the post's status before retrying.
- **Credentials and permissions:** the gate does not isolate your customers. Keep one key per customer and check permissions on your server.

## Doing this with APIWings

APIWings is a [unified social media API](https://apiwings.com/), so in this design it is **the publishing step: one request from your server after the post is approved**. **Bluesky, LinkedIn and X are live, and Instagram, Facebook Pages, Threads, TikTok and YouTube open as each network approves the integration** ([status](https://apiwings.com/changelog)). These features of the API fit the steps above ([quickstart](https://apiwings.com/docs/quickstart)):
- **Required idempotency key:** sending the same idempotency_key again returns the existing post and never publishes twice.
- **Keys scoped to one profile:** a key for one of your customers cannot post for another.
- **Cancel window:** posts with scheduled_at can be cancelled with DELETE /v1/posts/{id} until they start publishing.
- **TikTok screen data:** GET /v1/accounts/{id}/publish-options returns the live creator info your approval screen must show, once TikTok is available.
- **Real results:** each network's result arrives by signed webhook, with the visibility the network actually applied.

```json
{
  "profile_id": "...",
  "content": "Version 2 of Acme is out: plan a full month of posts in one view. https://acme.com/blog/v2",
  "platforms": [
    { "platform": "bluesky" }
  ],
  "scheduled_at": "2026-12-01T10:15:00Z",
  "idempotency_key": "agent-00c3d406001d573c7b59390c92822b7dd81270b8"
}
```

APIWings also has an MCP server for AI agents, which we will publish soon, and which keeps the API key in the server's environment and never in the conversation. **Its create_post tool publishes**, so it suits a person working with their own assistant, who sees and confirms each call. For agents that work for your customers, use the pattern in this guide: the agent drafts, your app checks and gets approval, and your server publishes.

## Free resources: agent post gate, policy template and tools

Everything in this guide is available to reuse. **The code is MIT and the data is CC BY 4.0.**
- **Agent post gate** for [JavaScript](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent-post-gate.mjs) and [Python](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent_post_gate.py): give it a draft, your policy and the account's history; it returns publish, needs_approval or blocked, the reasons, the approval hash and the idempotency key. No dependencies.
- **[Policy template (JSON)](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent-post-policy.json):** accounts, allowed domains, limits, secret patterns and the network rules from this guide, with a source link for each rule.
- **[Agent tools (JSON)](https://apiwings.com/blog/ai-agent-publish-social-media-posts/agent-tools.json):** the three least-privilege tools in MCP format.
- **[Worked example (JSON)](https://apiwings.com/blog/ai-agent-publish-social-media-posts/example-agent-proposals.json):** the eight posts above, to reproduce the result.
- [**Test cases (JSON)**](https://apiwings.com/blog/ai-agent-publish-social-media-posts/gate-test-cases.json) and test scripts for [Python](https://apiwings.com/blog/ai-agent-publish-social-media-posts/test_gate.py) and [JavaScript](https://apiwings.com/blog/ai-agent-publish-social-media-posts/test-gate.mjs): 420 cases, and both versions return identical results.
- **[Cheat sheet (PDF)](https://apiwings.com/blog/ai-agent-publish-social-media-posts/ai-agent-posting-cheat-sheet.pdf):** one page with the network rules, the four steps and the gate checks.
- **[README](https://apiwings.com/blog/ai-agent-publish-social-media-posts/README.md):** what each file is and how to run the tests.

![Preview of the one-page AI agent posting cheat sheet with network rules and checks](https://apiwings.com/blog/ai-agent-publish-social-media-posts/ai-agent-posting-cheat-sheet.webp)

*The AI agent posting cheat sheet: download the PDF to keep it next to your code.*

**Checking a draft takes one call.** In JavaScript (Node 18 or later):

```js
import { readFileSync } from "node:fs";
import { check } from "./agent-post-gate.mjs";

const policy = JSON.parse(readFileSync("./agent-post-policy.json", "utf8"));
const { cases } = JSON.parse(readFileSync("./example-agent-proposals.json", "utf8"));
const { proposal, state } = cases.find((c) => c.id === "B");

const result = check(proposal, policy, state);
console.log(result.decision);  // blocked
console.log(result.problems);  // [ 'link to acme-refunds.example.net is not on the allowed domains list' ]
```

**And in Python** (3.9 or later):

```python
import json
from agent_post_gate import check

policy = json.load(open("agent-post-policy.json", encoding="utf-8"))
cases = json.load(open("example-agent-proposals.json", encoding="utf-8"))["cases"]
for case in cases:
    result = check(case["proposal"], policy, case["state"])
    print(case["id"], result["decision"], result["problems"])
```

Run python test_gate.py or node test-gate.mjs to check your copy: **both print "420 of 420 cases pass"** (we ran them on Node 22 and Python 3.13).

## Checklist for letting an AI agent post
- **Give the agent one write tool** that saves a draft, never a publish, edit or delete tool.
- **Keep the publishing API key on your server**, scoped to one customer.
- **Check every draft in code:** accounts, links, secrets, mentions, alt text, limits, duplicates and network rules.
- **Show the exact post for approval**, and let TikTok users choose the privacy level and consent there.
- **Treat LinkedIn posts as drafts** the member approves, and check your workflow against LinkedIn's API terms.
- **Bind each approval to a hash of the content**, and let it expire.
- **Publish with an idempotency key**, log every decision, and keep a kill switch.

## FAQ

### Can an AI agent post to social media on its own?

Technically yes, if it has a tool that calls a publishing API. **Safely, it should only draft**: your code checks the draft, a person approves the exact post, and your server publishes it. LinkedIn's API terms restrict automated posting, and TikTok and Meta require the user's consent, so unattended posting is hard to reconcile with their rules.

### Is it allowed to let an AI agent post to LinkedIn?

LinkedIn provides official APIs for authorized apps to post for a member, but its API Terms of Use restrict using them to automate posting. **An agent can write the draft; the member should review and approve each post** before your app sends it. Approval alone does not guarantee compliance, so check with LinkedIn if your workflow is close to automated posting.

### Do I need MCP to let an agent post?

No. MCP is one way to give an agent tools; most tool-calling APIs work the same way, with a name, a description and a JSON schema. **What matters is what the tool can do**: a drafting tool is safe to expose, and a publishing tool should stay behind your own approval step.

### How do I stop prompt injection from publishing posts?

You cannot fully prevent prompt injection, according to OWASP, so **limit what it can do**: the agent only drafts, a gate in code blocks links to domains you do not allow, secrets and accounts outside the policy, and a person approves the final text.

### Do AI-written social media posts have to be labelled?

It depends on the network and the law. In the EU, from 2 August 2026, AI-generated text published to inform the public on matters of public interest must be disclosed, **unless it went through human review or editorial control** and someone holds editorial responsibility. Check each network's own rules on AI-generated content too.
