# twitter-fetch-posts > Fetch the latest posts and performance metrics for a Twitter/X user. ## Overview - **Endpoint**: `POST https://api.muapi.ai/api/v1/twitter-fetch-posts` - **Model ID**: `twitter-fetch-posts` - **Category**: other - **Variant**: Twitter / X Posts Scraper - **Family**: social-scraper - **Cost**: 0.01 credits per call (some models compute cost dynamically based on params) ## API Usage MuApi uses a **submit-then-poll** pattern: submit a job, get a `request_id`, then poll the predictions endpoint until `status` is `completed`. Optionally pass `?webhook=YOUR_URL` on the submit call to receive a POST callback when the job finishes (skip polling). **Authentication**: send your MuApi key in the `x-api-key` header. Get one at https://muapi.ai/access-keys. ### 1. Submit a job ```http POST https://api.muapi.ai/api/v1/twitter-fetch-posts Content-Type: application/json x-api-key: YOUR_API_KEY ``` **Minimum (required only):** ```json { "username": "" } ``` **Full example (all params):** ```json { "username": "", "count": 10, "cursor": null, "min_likes": "Any", "min_views": "Any", "min_shares": "Any", "min_comments": "Any", "min_duration": "Any", "max_duration": "Any", "hashtags": null, "published_after": null, "published_before": null } ``` **Response:** ```json { "request_id": "abc123", "status": "processing" } ``` ### 2. Poll for the result ```http GET https://api.muapi.ai/api/v1/predictions/{request_id}/result x-api-key: YOUR_API_KEY ``` Possible `status` values: `queued`, `pending`, `processing`, `completed`, `failed`, `cancelled`. Poll every 2-5 seconds until terminal. When `completed`, the result URLs are in the `outputs` array. **Example response when `completed`:** ```json { "id": "abc123", "status": "completed", "outputs": [ "https://cdn.muapi.ai/.../output.png" ], "urls": { "get": "https://api.muapi.ai/api/v1/predictions/abc123/result" }, "created_at": "2026-05-08T12:34:56Z", "has_nsfw_contents": [] } ``` ### cURL ```bash # 1. Submit REQUEST_ID=$(curl -s -X POST https://api.muapi.ai/api/v1/twitter-fetch-posts \ -H "x-api-key: $MUAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"username":""}' | jq -r .request_id) # 2. Poll until completed while :; do RESP=$(curl -s https://api.muapi.ai/api/v1/predictions/$REQUEST_ID/result -H "x-api-key: $MUAPI_API_KEY") STATUS=$(echo "$RESP" | jq -r .status) [ "$STATUS" = "completed" ] && echo "$RESP" | jq .outputs && break [ "$STATUS" = "failed" ] && echo "$RESP" && exit 1 sleep 3 done ``` ### Python ```python import os, time, requests API = "https://api.muapi.ai/api/v1" headers = {"x-api-key": os.environ["MUAPI_API_KEY"]} r = requests.post(f"{API}/twitter-fetch-posts", headers=headers, json={"username":""}) request_id = r.json()["request_id"] while True: res = requests.get(f"{API}/predictions/{request_id}/result", headers=headers).json() if res["status"] == "completed": print(res["outputs"]); break if res["status"] == "failed": raise RuntimeError(res.get("error")); time.sleep(3) ``` ## Input Schema The API accepts the following input parameters: - **`username`** (`text`, _required_): Twitter/X username. - **`count`** (`int`, _optional_): Number of posts to fetch (1 to 30). - Default: `10` - **`cursor`** (`text`, _optional_): Pagination cursor token to fetch the next page of results. - Default: `null` - **`min_likes`** (`string`, _optional_): Filter: Minimum number of likes. - Default: `"Any"` - Options: `"Any"`, `"100+"`, `"1k+"`, `"5k+"`, `"10k+"`, `"50k+"`, `"100k+"`, `"500k+"`, `"1M+"`, `"5M+"`, `"10M+"` - **`min_views`** (`string`, _optional_): Filter: Minimum number of views/plays. - Default: `"Any"` - Options: `"Any"`, `"100+"`, `"1k+"`, `"5k+"`, `"10k+"`, `"50k+"`, `"100k+"`, `"500k+"`, `"1M+"`, `"5M+"`, `"10M+"` - **`min_shares`** (`string`, _optional_): Filter: Minimum number of shares. - Default: `"Any"` - Options: `"Any"`, `"100+"`, `"1k+"`, `"5k+"`, `"10k+"`, `"50k+"`, `"100k+"`, `"500k+"`, `"1M+"`, `"5M+"`, `"10M+"` - **`min_comments`** (`string`, _optional_): Filter: Minimum number of comments. - Default: `"Any"` - Options: `"Any"`, `"100+"`, `"1k+"`, `"5k+"`, `"10k+"`, `"50k+"`, `"100k+"`, `"500k+"`, `"1M+"`, `"5M+"`, `"10M+"` - **`min_duration`** (`string`, _optional_): Filter: Minimum video duration. - Default: `"Any"` - Options: `"Any"`, `"15s"`, `"30s"`, `"45s"`, `"1m"`, `"2m"`, `"3m"`, `"5m"`, `"10m"` - **`max_duration`** (`string`, _optional_): Filter: Maximum video duration. - Default: `"Any"` - Options: `"Any"`, `"15s"`, `"30s"`, `"45s"`, `"1m"`, `"2m"`, `"3m"`, `"5m"`, `"10m"` - **`hashtags`** (`text`, _optional_): Filter: Comma-separated hashtags (e.g. startup,tech). - Default: `null` - **`published_after`** (`text`, _optional_): Filter: Fetch posts published after this date/time (ISO 8601). - Default: `null` - **`published_before`** (`text`, _optional_): Filter: Fetch posts published before this date/time (ISO 8601). - Default: `null` ## Output Schema The polling endpoint returns the following fields: - **`id`** (`string`): The request ID. - **`status`** (`string`): One of `queued`, `pending`, `processing`, `completed`, `failed`, `cancelled`. - **`outputs`** (`array`): URLs to generated images/videos/audio. Empty until `status` is `completed`. - **`urls.get`** (`string`): Self-link to re-fetch this prediction. - **`error`** (`string` | `null`): Error message if `status` is `failed`. - **`created_at`** (`string`): ISO-8601 timestamp of when the request was created. - **`has_nsfw_contents`** (`array of boolean`): Per-output NSFW detection flags. ## Webhooks (optional) Append `?webhook=https://your-server/path` to the submit URL. When the job reaches a terminal state, MuApi will POST the same shape as the polling response to your URL — no polling needed. ## Agent Integration MuApi ships an MCP server and CLI so agents (Claude Code, Cursor, custom) can call this endpoint without writing HTTP code: ```bash # Install the CLI npm install -g muapi-cli # Authenticate once muapi auth login # Expose all MuApi models as MCP tools to your agent muapi mcp serve ``` The MCP server exposes tools that wrap submit + poll for every model, including `twitter-fetch-posts`. See `muapi --help` for category-specific shortcuts (`muapi image generate`, `muapi video from-image`, etc.). ## Related Models - [Twitter / X Posts Scraper](https://muapi.ai/playground/twitter-fetch-posts) - [TikTok Profile Scraper](https://muapi.ai/playground/tiktok-fetch-profile) - [TikTok Videos Scraper](https://muapi.ai/playground/tiktok-fetch-videos) - [Instagram Reels Scraper](https://muapi.ai/playground/instagram-fetch-reels) - [YouTube Shorts Scraper](https://muapi.ai/playground/youtube-fetch-shorts) - [Facebook Reels Scraper](https://muapi.ai/playground/facebook-fetch-reels) ## Resources - [Playground Page](https://muapi.ai/playground/twitter-fetch-posts) - [API Reference](https://muapi.ai/playground/twitter-fetch-posts?tab=2) - [Global llms.txt](https://muapi.ai/llms.txt)