# Post a TikTok video from OpenCode

Prepare a vertical clip with OpenCode and check which visibility settings the connected TikTok account allows before approving an upload.

Canonical page: https://pubnio.com/opencode/tiktok

## Connect OpenCode

### Add PubNio to opencode.json

opencode mcp add writes the same entry. Remote servers sit under mcp.servers with type remote.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "pubnio": {
        "type": "remote",
        "url": "https://pubnio.com/mcp"
      }
    }
  }
}
```

Or from a terminal:

```sh
opencode mcp add pubnio --url https://pubnio.com/mcp
opencode mcp auth pubnio
```

### Sign in

1. Run opencode mcp auth pubnio, or run /mcps inside OpenCode and select pubnio.
2. Your browser opens PubNio sign-in; approve the workspace.

### Install the skill (optional)

```sh
npx skills add pubnio/agent-skills
```

Installs the pnio skill from skills.sh.

### Connect your TikTok account

[Open PubNio](https://pubnio.com/app), choose your workspace, and go to Accounts. Use the same workspace when you sign in from OpenCode.

- A TikTok creator account with Direct Post access through a connected PubNio integration.
- The video at an HTTPS URL, within the creator’s current upload limits. A public or signed HTTPS link PubNio can fetch. A file of up to 8 MiB can go inline as base64 instead.
- Explicit approval of the selected visibility, caption, and content disclosures.
- An audited TikTok integration for public visibility. Unaudited Direct Post is private-only.

### Check the destination

```
List the TikTok accounts in my PubNio workspace, which are ready to publish, and the allowed visibility options if available. Do not upload or post anything.
```

## Worked job: Prepare and approve a TikTok video

Contract example: sample IDs and URLs. The request and both responses decode against PubNio's API schemas; no provider confirmed this post.

### Prompt

```
Prepare https://cdn.example.com/walkthrough.mp4 for my ready TikTok account. Show the account, file, caption, visibility options, and any commercial disclosure or AI labeling required. Ask me to choose the visibility. Stop if the choice is unavailable. After I explicitly approve the final options, import the video, submit once, and check the same delivery. Report the confirmed TikTok post ID if available; otherwise return the PubNio post ID and latest status.
```

### What OpenCode runs: the Code Mode flow

```text
search   -> find the media-import, media-status, create-post, and read-post operations
execute  -> import media { url: "https://cdn.example.com/walkthrough.mp4" }
         => 202 { mediaId: "…", status: "processing" }
execute  -> read media status, sleep 1s between checks
         => { status: "ready" }
execute  -> create post { text: "…", publishNow: true, targets: [ { accountId: "…", provider: "tiktok", placement: "feed", settings: { format: "video", privacy: "PUBLIC_TO_EVERYONE", commercialDisclosure: "none" }, media: [ { mediaId: "…" } ] } ] }
            Idempotency-Key: opencode-tiktok-walkthrough
         => 202 { postId, targets: [tiktok/feed: queued] }
execute  -> read post, sleep 1s between checks, within the 30s budget
         => { status: "published", providerRef: { id: "991", kind: "post" } }
```

### Settled result (200 OK)

```json
{
  "postId": "00000000-0000-4000-8000-000000000002",
  "isDraft": false,
  "revision": 1,
  "scheduledAt": null,
  "text": "A short walkthrough of our editing workflow.",
  "media": [
    {
      "mediaId": "00000000-0000-4000-8000-000000000005"
    }
  ],
  "targets": [
    {
      "accountId": "00000000-0000-4000-8000-000000000001",
      "provider": "tiktok",
      "placement": "feed",
      "settings": {
        "format": "video",
        "privacy": "PUBLIC_TO_EVERYONE",
        "commercialDisclosure": "none"
      },
      "media": [
        {
          "mediaId": "00000000-0000-4000-8000-000000000005"
        }
      ]
    }
  ],
  "deliveries": [
    {
      "targetId": "00000000-0000-4000-8000-000000000003",
      "attemptId": "00000000-0000-4000-8000-000000000004",
      "accountId": "00000000-0000-4000-8000-000000000001",
      "provider": "tiktok",
      "placement": "feed",
      "canRetry": false,
      "canReconcile": false,
      "revision": 1,
      "status": "published",
      "providerRef": {
        "id": "991",
        "kind": "post"
      }
    }
  ],
  "status": "published",
  "createdAt": "2026-12-04T07:20:00.000Z",
  "updatedAt": "2026-12-04T07:20:18.000Z"
}
```

### From approval to delivery

Illustrative conversation and result with sample data.

**OpenCode:** Example Studio is ready and TikTok reports that public posting is available. Here’s walkthrough.mp4 and its proposed caption. Please confirm visibility and any required disclosures.

**You:** I reviewed the clip and caption. Use Public. No commercial disclosure applies to this clip.

**OpenCode:** PubNio accepted the submission. I waited for TikTok to return the final post ID before treating the delivery as published.

#### Example delivery result

- Status: `published`

- Destination: Example Studio · Public requested

## Check delivery and get the link

- Keep the PubNio post ID after the submission is accepted.
- Keep checking that submission while TikTok processes it.
- Treat a submission ID as progress. Wait for the final post ID before reporting confirmed publication.
- Verify the visibility in TikTok before describing the clip as public.

## TikTok rules OpenCode runs into

Account kinds: social account. Connection scopes: `video.publish`.

| Placement | Default | Media types | Max per target | Caption limit |
| --- | --- | --- | --- | --- |
| `feed` | Yes | image, video | 35 | 2,200 |

- TikTok's feed placement takes up to 35 images or videos; this walkthrough posts one video.
- Captions run up to 2,200 characters.
- Choose one of the visibility options available to the connected creator.
- Check the creator’s current duration and upload limits before submitting.
- Confirm the caption, visibility and applicable content disclosures before the write.

## Failures and recovery

### TikTok issue codes

| Code | Cause | Fix | Retry |
| --- | --- | --- | --- |
| `account_not_ready` | The connected account's OAuth token is expired, revoked, or disconnected. | Reconnect the account in the PubNio workspace, then re-validate. | After reconnect |
| `tiktok_privacy_unsupported` | Requested `privacy` level is not permitted for the creator account. | Inspect allowed privacy levels on the account (unaudited apps require `SELF_ONLY`). | No |
| `tiktok_disclosure_required` | Commercial/branded content disclosure flag is required for the selected settings. | Set explicit commercial disclosure fields in target `settings`. | No |
| `tiktok_upload_required` | TikTok target requires staged video or photo upload media. | Import media into PubNio first and attach `{ mediaId }` entries. | No |
| `tiktok_too_many_mentions` | Caption exceeds TikTok's allowed `@mention` count. | Reduce the number of `@mentions` in the TikTok target caption. | No |

### OpenCode setup problems

- Calls start failing with 401. Run opencode mcp auth pubnio again to renew the PubNio sign-in.
- OpenCode does not list pubnio in /mcps. Check that the entry is under mcp.servers with type remote in opencode.json.
- Writes fail with 403 read_only_mode. PubNio returns 403 read_only_mode when the server URL ends in ?readOnly=1. Point the entry at https://pubnio.com/mcp to allow writes.

### OpenCode quirks

- You can sign in from the CLI (opencode mcp auth pubnio) or from /mcps inside a session.
- A remote server needs type remote under mcp.servers; a bare url entry is not enough.

## What it won't do

- Post publicly through an unaudited TikTok integration. TikTok keeps those posts private.
- Pick visibility or disclosures on your behalf. OpenCode has to ask you.
- Connect accounts, create API keys, or manage webhooks from an MCP session that uses an API key. Those operations need a person signed in, so connect the MCP server with browser OAuth or use the PubNio web app.
- Stream binary uploads through execute. Import media from an HTTPS URL, or send a file of up to 8 MiB inline as base64.
- Run one execute call past 30 seconds or past its request limit. The script returns the post ID so the next call can check it.

## Frequently asked questions

### Can every TikTok account post publicly through an API?

Public visibility depends on the integration’s audit and the creator’s allowed settings. TikTok restricts unaudited integrations to private viewing.

### Can OpenCode choose my privacy settings for me?

Ask OpenCode to show you the available choices and wait for you to approve one.

### Is a TikTok submission ID a published post ID?

A submission ID tracks processing. PubNio needs the final post ID to confirm a publication.

### What if the upload is still processing?

Keep the original PubNio post ID and query its delivery again. Avoid starting another upload while the first is unresolved.

### Where does OpenCode keep the PubNio server?

In opencode.json under mcp.servers.pubnio with type remote and url https://pubnio.com/mcp. opencode mcp add writes it for you.

### Can I sign OpenCode in without leaving the session?

Yes. Run /mcps, select pubnio, and approve the workspace in your browser.

## Also works with

- [Post a TikTok video from Claude Code](https://pubnio.com/claude/tiktok)
- [Post a TikTok video from Codex](https://pubnio.com/codex/tiktok)
- [Post a TikTok video from Cursor](https://pubnio.com/cursor/tiktok)
- [Post to Instagram from OpenCode](https://pubnio.com/opencode/instagram)
- [Post to LinkedIn from OpenCode](https://pubnio.com/opencode/linkedin)
- [Upload YouTube Shorts from OpenCode](https://pubnio.com/opencode/youtube)
- [Post to a Facebook Page from OpenCode](https://pubnio.com/opencode/facebook)
- [Create a Pinterest Pin from OpenCode](https://pubnio.com/opencode/pinterest)
- [Publish an X thread from OpenCode](https://pubnio.com/opencode/x)
- [OpenCode setup](https://pubnio.com/opencode)
- [TikTok publishing API](https://pubnio.com/platforms/tiktok)
- [TikTok MCP](https://pubnio.com/tiktok-mcp)
- [TikTok network reference](https://pubnio.com/docs/networks/tiktok/)
- [TikTok error codes](https://pubnio.com/docs/errors/tiktok/)
- [Pricing](https://pubnio.com/pricing)

## Get started with PubNio

Connect unlimited accounts at $0 per account. Pay as you go includes 50 free confirmed publishes a month on your first workspace, then $20 per 1,000. X API fees are separate.

## REST API reference

Contract example: sample IDs and URLs. The request and both responses decode against PubNio's API schemas; no provider confirmed this post.

```http
POST /api/v1/posts?workspaceId=00000000-0000-4000-8000-000000000006
Authorization: Bearer pn_live_***
Idempotency-Key: opencode-tiktok-walkthrough
Content-Type: application/json

{
  "text": "A short walkthrough of our editing workflow.",
  "publishNow": true,
  "targets": [
    {
      "accountId": "00000000-0000-4000-8000-000000000001",
      "provider": "tiktok",
      "placement": "feed",
      "settings": {
        "format": "video",
        "privacy": "PUBLIC_TO_EVERYONE",
        "commercialDisclosure": "none"
      },
      "media": [
        {
          "mediaId": "00000000-0000-4000-8000-000000000005"
        }
      ]
    }
  ]
}
```

### 202 Accepted

```json
{
  "postId": "00000000-0000-4000-8000-000000000002",
  "idempotencyKey": "opencode-tiktok-walkthrough",
  "targets": [
    {
      "targetId": "00000000-0000-4000-8000-000000000003",
      "attemptId": "00000000-0000-4000-8000-000000000004",
      "accountId": "00000000-0000-4000-8000-000000000001",
      "provider": "tiktok",
      "placement": "feed",
      "canRetry": false,
      "canReconcile": false,
      "status": "queued",
      "scheduledAt": null,
      "url": null,
      "issue": null
    }
  ],
  "warnings": []
}
```

