Skip to content
UGC API

How to let an AI agent post to TikTok and Instagram (safely)

Agents can now write the hook, pick the account and post it. The hard part isn't the call, it's making sure the agent posts the right thing to the right account at the right time. Here are the two ways to wire it up, and the guardrails we'd put on each.

Updated

Two ways to connect an agent

Interactive (MCP)Autonomous (REST tool calling)
Who is in the loopA person chatting with the assistantNobody, or a person reviewing later
ExamplesClaude, ChatGPT, Cursor, VS Code, Gemini CLIOpenAI Agents SDK, LangChain, CrewAI, Grok via the xAI API, your own loop
AuthOAuth sign-in and consent screenAuthorization: Bearer ugc_live_… API key
Endpointhttps://ugcapi.dev/mcphttps://ugcapi.dev/v1/…
Best forMarketers planning and checking posts in chatPipelines that generate and post on a schedule

Both paths end at the same place: the same posting engine, the same credits ($10 per 1,000 posts), the same platform rules. Pick by asking who approves each post.

Path 1: an assistant over MCP

Add https://ugcapi.dev/mcp as a connector or MCP server in your assistant, sign in, and approve access. The assistant gets 15 tools, from list_accounts to create_campaign. Setup per client is in the MCP docs; walkthroughs for Claude and ChatGPT are separate guides.

A typical request: "Post https://cdn.example.com/clip.mp4 to my TikTok and as an Instagram Reel plus Story tomorrow at 9am London. Caption: 3 desk upgrades under $30." The assistant calls list_accounts, then get_creator_info for the TikTok account, shows you the plan and asks for TikTok privacy, then calls publish_post once you agree.

Path 2: an autonomous agent with tool calling

For an agent that runs without a chat window, describe one or two REST endpoints as tools and give the agent an API key stored on your server. Keep the tool surface small: an agent that can only call POST /v1/posts with drafts on is much easier to trust than one that can also cancel campaigns.

json
{
  "type": "function",
  "function": {
    "name": "publish_post",
    "description": "Schedule one UGC post to connected social accounts via UGC API.",
    "parameters": {
      "type": "object",
      "required": ["accounts", "format", "media", "caption", "scheduled_at"],
      "properties": {
        "accounts": { "type": "array", "items": { "type": "string" } },
        "format": { "type": "string", "enum": ["video", "slideshow", "image"] },
        "media": { "type": "array", "items": { "type": "string", "format": "uri" } },
        "caption": { "type": "string", "maxLength": 2200 },
        "scheduled_at": { "type": "string", "format": "date-time" }
      }
    }
  }
}

Your code receives the tool call, validates it, adds the fixed options you decided on (drafts, privacy, AI label), and sends it to POST https://ugcapi.dev/v1/posts. The agent never sees the key. Full examples for Grok and for agent frameworks.

Guardrails we recommend

  1. Allowlist accounts. Don't let the model choose from every account in the workspace. Pass the allowed account ids in the system prompt and reject anything else in your tool handler.
  2. Schedule, don't post now. Make scheduled_at required and at least an hour out. That gives you a window to look at upcoming posts with GET /v1/posts?sort=scheduled_at and cancel with DELETE /v1/posts/:id, which refunds the credit.
  3. Use TikTok drafts while you build trust. With options.tiktok.draft: true, the video lands in the creator's TikTok inbox to finish and post by hand, which also lets them add a trending sound.
  4. Preview bulk work. For more than a few posts, have the agent call preview_campaign (MCP) or build the plan and show it before create_campaign. A preview costs nothing and shows every time and account.
  5. Set privacy explicitly. TikTok makes the creator choose privacy. In a chat, the assistant must ask. In an autonomous pipeline, decide the level once per account and set options.tiktok.privacy in code.
  6. Label AI content. If the agent posts AI-generated video, set options.tiktok.ai_generated: true. See the TikTok AI label guide.
  7. Cap spend. Keep a separate workspace with a small credit balance for an experimental agent. When credits run out, posts are refused, not charged.

Close the loop with webhooks and stats

An agent that posts and forgets will repeat its mistakes. Subscribe to post.published and post.failed webhooks, store the result, and feed failures back into the agent's next run ("the Instagram video was rejected: aspect ratio"). Failed results refund their credit automatically.

For performance, GET /v1/stats returns results by status, platform and day, plus views, likes, comments, shares and saves read back from Instagram and TikTok every hour, and the top posts by views. That's enough for an agent to decide what to make more of. See the agentic UGC pipeline.

A system prompt that keeps agents in line

Guardrails in code are the real protection, but a clear system prompt saves a lot of rejected tool calls. Something like this works for a posting agent:

text
You schedule short-form posts for Desk Co.
- Only use these accounts: acc_tt_main (TikTok), acc_ig_main (Instagram).
- Never schedule sooner than 60 minutes from now, or more than 3 posts per account per day.
- Captions: under 150 characters, one question, at most 3 hashtags, no prices.
- Never repeat a video URL that appears in the "already posted" list.
- If a tool returns an error, explain it and stop. Do not retry more than once.

Give the agent the list of what's already posted (from GET /v1/posts) at the start of each run. Agents forget between runs, and duplicate posts are the most common mistake we see.

A rollout plan

  1. Week 1: suggest only. The agent writes captions and picks slots; a person creates the posts.
  2. Week 2: drafts. The agent schedules TikTok posts as drafts and Instagram posts at least a day ahead. A person reviews the upcoming list daily.
  3. Week 3: one account live. One account posts without review, the rest stay on drafts. Compare failure rates and engagement.
  4. After that: widen to more accounts, keep the scheduling buffer, and keep webhooks alerting on failures.

What the agent still can't do

  • Post from a chat attachment. Media must be a public https URL, or uploaded first with upload_media_from_url or POST /v1/media.
  • Skip platform caps. TikTok and Instagram limit how many posts an app can publish per account per day. See limits.
  • Post publicly on TikTok before the platform approves the app. Until TikTok's audit completes, new apps can only post privately.
  • Connect an account without the owner. Each creator signs in on the platform's own page through a connect link.

FAQ

Should I use MCP or the REST API for my agent?

MCP when a person chats with the assistant and approves posts. The REST API with an API key when the agent runs on its own in your backend.

Can an agent post to TikTok without the creator choosing privacy?

In chat, no: the MCP tool refuses a TikTok post without a privacy choice. In your own pipeline, you set options.tiktok.privacy in code after the creator has chosen it in your product.

How do I stop an agent from posting something wrong?

Schedule posts at least an hour ahead, review upcoming posts, and cancel anything off. Cancelled posts are refunded. TikTok drafts add a manual step too.

Does UGC API generate the content?

No. Your agent or generator makes the video, slideshow or image and caption. UGC API publishes it and reports the results.

Related