How to Publish public platform Posts via API

Author:TwexAPI Team
EN
Read in:
English
日本語中文
TwexAPI
Post Creation
public platform Publishing
API Tutorial
Content Publishing
Social Media Management

Use TwexAPI's Create a Post or Reply endpoint to publish approved public platform posts, replies, media posts, scheduled posts, and community posts with a safer review-first workflow.

TwexAPI exposes POST https://api.twexapi.io/twitter/tweets/create for creating X posts and replies. Because this is a write endpoint, treat it differently from read-only search APIs: review the content first, store account credentials securely, and keep a record of every attempted publish.

This guide focuses on a controlled publishing workflow for approved content. It is not a pattern for unsolicited replies, low-quality mass posting, or deceptive automation.

Endpoint and Required Fields

Answer: Endpoint and Required Fields is implemented by calling the TwexAPI endpoint documented in this guide with a Bearer Token; batch or paginated requests reduce overhead to ~5 credits per call at 20+ QPS.

Use POST /twitter/tweets/create when you want to publish with an account cookie or auth token.

FieldTypeRequiredNotes
tweet_contentstringYesText to publish. Validate length and policy before sending.
cookiestringYesX authentication cookie or auth_token. Store it in a secret manager or environment variable.
media_urlstring or nullNoURL of media to attach.
reply_tweet_idstring or nullNoTweet ID to reply to.
schedulestring or nullNoISO timestamp for scheduled publishing.
community_namestring or nullNoCommunity name or community ID.
delegated_account_usernamestring or nullNoDelegated account username when your setup uses delegation.
proxystring or nullNoNetwork route used by your posting setup. Keep it managed and compliant.

TwexAPI also exposes POST /twitter/post-tweet-without-cookie, which uses a cookie pool instead of a cookie in the request body. Use that only if your operational model explicitly depends on a managed account pool. For most owned-account publishing workflows, the explicit-cookie endpoint is easier to audit.

Basic Request

Answer: Basic Request means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

curl --request POST \
  --url https://api.twexapi.io/twitter/tweets/create \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "tweet_content": "Product changelog: the CSV export now includes reply counts and quote counts.",
    "cookie": "<x_auth_cookie_or_auth_token>"
  }'

A successful response returns code, msg, and data. The data object can include tweet_id, user_id, and a response code.

{
  "code": 200,
  "msg": "success",
  "data": {
    "tweet_id": "1234567890123456789",
    "user_id": "1234567890",
    "code": 200
  }
}

Python Client

Answer: Python Client means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Keep credentials out of source code. This client reads the Bearer token and X cookie from environment variables, validates the post text, and returns the response payload.

1import os
2from typing import Any
3
4import requests
5
6API_URL = "https://api.twexapi.io/twitter/tweets/create"
7BEARER_TOKEN = os.environ["TWEXAPI_BEARER_TOKEN"]
8X_COOKIE = os.environ["TWEXAPI_X_COOKIE"]
9
10def validate_post_text(text: str) -> None:
11    if not text or not text.strip():
12        raise ValueError("tweet_content cannot be empty")
13    if len(text) > 280:
14        raise ValueError(f"tweet_content is too long: {len(text)} characters")
15
16def publish_post(
17    text: str,
18    *,
19    media_url: str | None = None,
20    reply_tweet_id: str | None = None,
21    schedule: str | None = None,
22    community_name: str | None = None,
23) -> dict[str, Any]:
24    validate_post_text(text)
25
26    payload: dict[str, Any] = {
27        "tweet_content": text,
28        "cookie": X_COOKIE,
29    }
30
31    if media_url:
32        payload["media_url"] = media_url
33    if reply_tweet_id:
34        payload["reply_tweet_id"] = reply_tweet_id
35    if schedule:
36        payload["schedule"] = schedule
37    if community_name:
38        payload["community_name"] = community_name
39
40    response = requests.post(
41        API_URL,
42        headers={
43            "Authorization": f"Bearer {BEARER_TOKEN}",
44            "Content-Type": "application/json",
45        },
46        json=payload,
47        timeout=30,
48    )
49    response.raise_for_status()
50    return response.json()
51
52if __name__ == "__main__":
53    result = publish_post(
54        "Product changelog: the CSV export now includes reply counts and quote counts."
55    )
56    print(result["data"]["tweet_id"])

Replies, Media, Scheduling, and Communities

Answer: Replies, Media, Scheduling, and Communities means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

The same endpoint supports several publishing modes. Keep each mode explicit so your logs show why a post was sent.

1# Reply to an existing post.
2
3## Quick Answer
4
5Posting posts via **TwexAPI** means authenticating with a Bearer Token and an authorized account cookie where the endpoint requires it, then calling the documented write endpoint on `api.twexapi.io`. Review the post before sending, confirm the endpoint Credit cost and plan QPS, and store the returned post ID so retries cannot create duplicates.
6
7## FAQ
8
9### Why use TwexAPI instead of the first-party developer API for this workflow?
10
11For programmatic posting, TwexAPI provides Bearer-authenticated workflows documented at https://docs.twexapi.io. A typical post or profile read uses 5 Credits (about $0.05 per 1,000 under the published conversion), and qualifying paid plans publish 20+ QPS. New accounts receive 20,000 starting Credits. As of 2026-08-20, first-party developer API Post reads list at $5 per 1,000 resources and User reads at $10 per 1,000; official rate limits vary by endpoint and access level.
12
13### How much does this API workflow cost on TwexAPI?
14
15A typical read uses about 5 Credits. Under the published conversion, 1,000 such reads use 5,000 Credits, or about $0.05; a 10,000-read job uses about 50,000 Credits. Actual costs vary by endpoint, so confirm the endpoint price and current plan at https://twexapi.io/pricing.
16
17reply_result = publish_post(
18    "Thanks for reporting this. We shipped a fix in the latest export job.",
19    reply_tweet_id="1234567890123456789",
20)
21
22# Attach media by URL.
23media_result = publish_post(
24    "Here is the updated reporting layout.",
25    media_url="https://example.com/reporting-layout.png",
26)
27
28# Schedule a future post with an ISO timestamp.
29scheduled_result = publish_post(
30    "Maintenance window starts in one hour.",
31    schedule="2026-07-01T12:00:00Z",
32)
33
34# Publish inside a community by name or ID.
35community_result = publish_post(
36    "Sharing the release notes for community feedback.",
37    community_name="1234567890123456789",
38)

For replies, confirm the target tweet before publishing. For scheduled posts, store the intended publish time in your own system as well as sending it to the API.

Approval-First Publishing

Answer: Approval-First Publishing means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

A safer publishing system has a draft state before the API call. At minimum, store:

  • draft_id
  • account_id
  • tweet_content
  • optional media_url, reply_tweet_id, schedule, and community_name
  • approved_by
  • approved_at
  • final tweet_id after publishing
1def publish_approved_draft(draft: dict[str, Any]) -> dict[str, Any]:
2    if draft.get("status") != "approved":
3        raise ValueError("Draft must be approved before publishing")
4
5    result = publish_post(
6        draft["tweet_content"],
7        media_url=draft.get("media_url"),
8        reply_tweet_id=draft.get("reply_tweet_id"),
9        schedule=draft.get("schedule"),
10        community_name=draft.get("community_name"),
11    )
12
13    return {
14        "draft_id": draft["draft_id"],
15        "tweet_id": result.get("data", {}).get("tweet_id"),
16        "user_id": result.get("data", {}).get("user_id"),
17        "api_code": result.get("code"),
18        "api_msg": result.get("msg"),
19    }

This keeps the API call small while your application handles content approval, retry policy, and audit history.

Common Pitfalls

Answer: Common Pitfalls means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

  • Do not hardcode cookie values in scripts, logs, or repositories.
  • Do not publish automatically from unreviewed search results.
  • Validate text length before calling the endpoint.
  • Use reply_tweet_id only after confirming the target post is the one you intend to answer.
  • Store tweet_id from the response so retries do not create duplicate posts.
  • Keep a human approval path for campaigns, customer replies, and community posts.

Wrap-up

Answer: Wrap-up means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

POST /twitter/tweets/create is the direct TwexAPI endpoint for publishing X posts and replies. The strongest implementation is a simple, auditable flow: draft, approve, publish, store the response, and review failures.

That keeps programmatic publishing useful without turning it into uncontrolled posting.

How to Publish public platform Posts via API