> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Analyze an X post with AI

> Ask a question about any public X post and its replies, and get an answer from AI.

> [!NOTE]
>
> Needs `posts:read`. See [Permissions](/docs/essentials/authentication.md#permissions).

Reads a public X post and up to 300 of its replies, and answers your `question` about them with AI. The post doesn't need to be in PostSyncer. For a post with more replies, the AI is told how many it has and that 300 were read. The answer also has the post's numbers (`tweet.metrics`) and the credits it cost.

It costs 1 AI credit. With `workspace_id` the workspace owner pays; without it, the key's user does. The balance is checked before the post is read, and you aren't charged when the AI can't answer.

## Free plan

AI post analysis is on paid plans. When the payer is on Free, it is refused with `403`, `error: plan_limit_reached`, `limit: ai`, before the post is read.

## Errors

| Status | `error` | When | Retry? |
| - | - | - | - |
| 401 | | No API key, or not a valid one. | No: fix the key. |
| 402 | `insufficient_credits` | The payer's AI credits don't cover it. | After topping up credits. |
| 403 | | The key lacks `posts:read`, or its user is inactive. | No: grant it in Settings → API. |
| 403 | `plan_limit_reached` | The payer is on the Free plan (`limit: ai`). | No: the payer upgrades. |
| 422 | | The link isn't an X post, the post couldn't be read, or `workspace_id` isn't one the key can reach. | No: fix the request. |
| 422 | `ai_declined` | The AI won't answer this question. | Yes, with other wording. |
| 422 | `ai_answer_too_long` | The answer was too long to finish. | Yes, with a shorter question. |
| 429 | | More than 60 requests a minute. | Yes, after `Retry-After` seconds. |
| 503 | `ai_unavailable` | The AI couldn't answer right now. | Yes, in a minute. |

## Related

* [Get a post by its link](/docs/api-reference/posts/get-by-url.md): a post you published with PostSyncer.
* [Get a post](/docs/api-reference/posts/get.md): numbers for your own posts.


## OpenAPI

````yaml POST /posts/analyze-twitter
openapi: 3.0.3
info:
  title: PostSyncer API
  description: >-
    Post to 12 social networks from your code: posts, media, comments,
    analytics, webhooks and more.
  version: 1.0.0
servers:
  - url: https://postsyncer.com/api/v1
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: The workspaces the key can reach.
  - name: Accounts
    description: Connected social accounts, links to connect more, and disconnecting them.
  - name: Posts
    description: Drafts, scheduled and published posts, approvals and a post's history.
  - name: Post settings
    description: A post's auto-plug, comment moderation and contact collection.
  - name: Media
    description: >-
      The media library: file uploads, URL imports, and reading videos and
      social posts' files.
  - name: Folders
    description: Folders that organise the media library.
  - name: Comments
    description: >-
      Comments on your posts: reading, replying, editing, hiding, deleting and
      syncing them.
  - name: Reviews
    description: Google Business Profile reviews and your replies to them.
  - name: Analytics
    description: Workspace, account and post performance.
  - name: Brand
    description: >-
      A workspace's brand: identity, voice, look, accounts, competitors,
      learnings and rules.
  - name: Labels
    description: Labels used to tag posts.
  - name: Campaigns
    description: Campaigns used to group posts.
  - name: Snippets
    description: Saved snippets and hashtag groups to drop into posts.
  - name: Webhooks
    description: Signed webhook endpoints that get your notification events.
  - name: Billing
    description: >-
      The owner's plan, invoices and the links that pay for, change or cancel
      it.
  - name: Team
    description: A workspace's teammates and invitations, and their roles.
  - name: Notifications
    description: >-
      Your bell and notification settings, and the workspace's Slack, Discord
      and Telegram channels.
  - name: Blog-to-social
    description: Blog feeds that turn a workspace's new articles into posts.
  - name: Products
    description: Products the workspace's posts can promote.
  - name: Contacts
    description: People who commented on the workspace's posts, and the lists they are on.
  - name: Profile
    description: 'The key''s user: their name and sign-in email.'
  - name: API keys
    description: 'Your API keys: listing and deleting them.'
  - name: Agent sign-up
    description: >-
      An AI agent signs a person up with a code emailed to them, and gets their
      first key. No key needed.
paths:
  /posts/analyze-twitter:
    post:
      tags:
        - Posts
      summary: Analyze an X post with AI
      description: >-
        Needs `posts:read`. Reads a public X post and up to 300 of its replies,
        and answers your question about them with AI. The post doesn't need to
        be in PostSyncer. It costs 1 AI credit: the workspace owner's with
        `workspace_id`, else the key's user's. It is on paid plans only: on Free
        it is refused with `403` `plan_limit_reached`, `limit: ai`, before the
        post is read.
      operationId: analyzeTwitterPost
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - url
                - question
              properties:
                url:
                  type: string
                  format: uri
                  maxLength: 2048
                  description: >-
                    The X post's link, like
                    `https://x.com/haldencoffee/status/1900812345678901234`.
                question:
                  type: string
                  minLength: 3
                  maxLength: 2000
                  description: What to find out from the post and its replies.
                workspace_id:
                  type: integer
                  description: >-
                    The workspace whose owner pays the credit; one the key can
                    reach. Leave it out and the key's user pays.
            examples:
              default:
                summary: Ask about the replies
                value:
                  url: https://x.com/haldencoffee/status/1900812345678901234
                  question: What do people ask about most in the replies?
                  workspace_id: 12
      responses:
        '200':
          description: The answer, the post's numbers, and the credits.
          content:
            application/json:
              schema:
                type: object
                required:
                  - answer
                  - tweet
                  - credits
                properties:
                  answer:
                    type: string
                  tweet:
                    type: object
                    required:
                      - id
                      - url
                      - text
                      - author
                      - created_at
                      - metrics
                    properties:
                      id:
                        type: string
                      url:
                        type: string
                        description: The link you sent.
                      text:
                        type: string
                        nullable: true
                      author:
                        type: string
                        nullable: true
                        description: The author's handle with `@`.
                      created_at:
                        type: string
                        nullable: true
                        description: When it was posted, as X writes it.
                      metrics:
                        type: object
                        required:
                          - likes
                          - replies
                          - reposts
                          - views
                          - quotes
                          - bookmarks
                        properties:
                          likes:
                            type: integer
                          replies:
                            type: integer
                          reposts:
                            type: integer
                          views:
                            type: integer
                          quotes:
                            type: integer
                          bookmarks:
                            type: integer
                  credits:
                    type: object
                    required:
                      - charged
                      - left
                    description: What the answer cost and what the payer has left.
                    properties:
                      charged:
                        type: integer
                      left:
                        type: integer
              examples:
                default:
                  summary: An answer
                  value:
                    answer: >-
                      Most replies ask whether the lavender latte comes with oat
                      milk, and a few ask for a decaf version. People who tried
                      it mostly like it; two say it is too sweet.
                    tweet:
                      id: '1900812345678901234'
                      url: https://x.com/haldencoffee/status/1900812345678901234
                      text: >-
                        Our spring menu starts today. The lavender oat latte is
                        back, and so is the rhubarb bun.
                      author: '@haldencoffee'
                      created_at: Fri Mar 15 09:00:12 +0000 2030
                      metrics:
                        likes: 312
                        replies: 46
                        reposts: 18
                        views: 15240
                        quotes: 3
                        bookmarks: 27
                    credits:
                      charged: 1
                      left: 239
        '401':
          $ref: '#/components/responses/Unauthorized401'
        '402':
          description: The payer's AI credits don't cover it. Nothing was charged.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InsufficientCreditsError'
              examples:
                insufficient_credits:
                  summary: No credits left
                  value:
                    message: >-
                      Not enough AI credits: this needs 1 and you have 0. Top up
                      your credits or upgrade your plan to continue.
                    error: insufficient_credits
                    credits_required: 1
                    credits_available: 0
        '403':
          description: >-
            The key lacks `posts:read`, its user is inactive, or the payer is on
            the Free plan (`plan_limit_reached`, `limit: ai`). Nothing was read
            or charged.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/PlanLimitError'
                  - $ref: '#/components/schemas/Error'
              examples:
                missing_permission:
                  summary: The key lacks posts:read
                  value:
                    message: >-
                      This API key does not have the "posts:read" permission.
                      Edit the key in PostSyncer under Settings → API to grant
                      it.
                ai_paid:
                  summary: 'Free: AI post analysis is paid'
                  value:
                    message: >-
                      AI post analysis is part of the paid plans. Upgrade to use
                      it.
                    owner_plan: false
                    error: plan_limit_reached
                    limit: ai
                    used: 0
                    allowed: 0
                    plan: free
                    resets_at: null
                    upgrade_url: >-
                      https://app.postsyncer.com/dashboard?action=settings&section=billing
                    upgrade_plan:
                      plan: starter-v2
                      name: Starter
                      monthly_price: 29
                      yearly_price: 24
                      accounts: 10
                      accounts_per_workspace: false
                inactive_account:
                  summary: The key's user is inactive
                  value:
                    message: Your account is inactive.
        '422':
          description: >-
            The request didn't pass validation, the post couldn't be read, or
            the AI wouldn't or couldn't finish the answer (`ai_declined`,
            `ai_answer_too_long`). You weren't charged.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/ValidationError'
                  - allOf:
                      - $ref: '#/components/schemas/Error'
                      - type: object
                        required:
                          - error
                        properties:
                          error:
                            type: string
                            enum:
                              - ai_declined
                              - ai_answer_too_long
              examples:
                not_an_x_link:
                  summary: Not an X post link
                  value:
                    message: The URL must be a valid X/Twitter post link.
                    errors:
                      url:
                        - The URL must be a valid X/Twitter post link.
                unreadable:
                  summary: The post couldn't be read
                  value:
                    message: >-
                      Unable to fetch the tweet. Please check the URL and try
                      again.
                    errors:
                      url:
                        - >-
                          Unable to fetch the tweet. Please check the URL and
                          try again.
                ai_declined:
                  summary: The AI declined
                  value:
                    error: ai_declined
                    message: >-
                      The AI won't write this. Try different wording. You
                      weren't charged.
                ai_answer_too_long:
                  summary: The answer was too long
                  value:
                    error: ai_answer_too_long
                    message: >-
                      The answer was too long to finish. Try a shorter text. You
                      weren't charged.
        '429':
          $ref: '#/components/responses/RateLimited429'
        '503':
          description: >-
            The AI couldn't answer right now. You weren't charged; try again in
            a minute.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - type: object
                    required:
                      - error
                    properties:
                      error:
                        type: string
                        enum:
                          - ai_unavailable
              examples:
                ai_unavailable:
                  summary: The AI is unavailable
                  value:
                    error: ai_unavailable
                    message: >-
                      The AI couldn't answer right now. Try again in a minute.
                      You weren't charged.
components:
  responses:
    Unauthorized401:
      description: No API key, or not a valid one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            unauthenticated:
              summary: No valid API key
              value:
                message: Unauthenticated.
    RateLimited429:
      description: >-
        More than 60 requests in a minute from this key's user (the API and the
        MCP server share the count). Wait `Retry-After` seconds.
      headers:
        Retry-After:
          description: Seconds until requests are allowed again.
          schema:
            type: integer
        X-RateLimit-Limit:
          description: Requests allowed a minute.
          schema:
            type: integer
        X-RateLimit-Remaining:
          description: Requests left this minute.
          schema:
            type: integer
        X-RateLimit-Reset:
          description: When requests are allowed again, as a Unix timestamp.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            too_many_attempts:
              summary: Too many requests
              value:
                message: Too Many Attempts.
  schemas:
    InsufficientCreditsError:
      type: object
      description: '402: the AI credits left don''t cover this.'
      required:
        - message
        - error
        - credits_required
        - credits_available
      properties:
        message:
          type: string
          description: What it needs, what is left, and what to do.
        error:
          type: string
          enum:
            - insufficient_credits
        credits_required:
          type: integer
          description: The credits this needs.
        credits_available:
          type: integer
          description: The credits left.
        free_plan:
          type: boolean
          enum:
            - true
          description: Only on the Free plan, whose credits come back each month.
        resets_at:
          type: string
          format: date-time
          description: 'Only on the Free plan: when its credits come back.'
    PlanLimitError:
      type: object
      description: >-
        403: the workspace owner's plan doesn't include this, or its limit is
        used up. Nothing was saved. `limit` says which.
      required:
        - message
        - owner_plan
        - error
        - limit
        - used
        - allowed
        - plan
        - resets_at
        - upgrade_url
        - upgrade_plan
      properties:
        message:
          type: string
          description: What the plan doesn't allow, and what to do.
        owner_plan:
          type: boolean
          description: >-
            True when the plan is someone else's (the key's user isn't the
            workspace owner): only the owner can change it, and `message` says
            to ask them.
        error:
          type: string
          enum:
            - plan_limit_reached
        limit:
          type: string
          enum:
            - accounts
            - posts
            - workspaces
            - team
            - labels
            - campaigns
            - ai
            - moderation
            - contacts
            - crm
            - products
            - analytics
            - free_accounts
          description: >-
            What ran out: `accounts`, `posts` (this month's posts) and
            `workspaces` are counted; `free_accounts` is a post to an account
            other than the 2 a Free owner posts to outside a first week (the
            account's `plan_allows_posting` is `false`); `team`, `labels`,
            `campaigns`, `ai`, `moderation` (comment moderation), `contacts`
            (contact collection), `crm` (contacts and contact lists) and
            `products` are on paid plans only. `analytics` (more than the last 7
            days) comes from the app only: API v1 and MCP don't refuse analytics
            on Free, they keep the numbers to the last 7 days, outside an
            owner's first week, and say so in `range_limited`.
        used:
          type: integer
          description: How much of the limit is used; 0 for a paid-plan feature.
        allowed:
          type: integer
          description: What the plan allows; 0 for a paid-plan feature.
        plan:
          type: string
          description: The owner's plan, like `free`.
        resets_at:
          type: string
          format: date-time
          nullable: true
          description: When a monthly limit starts again; null for the others.
        upgrade_url:
          type: string
          nullable: true
          description: Where the owner picks a plan; null when the plan is someone else's.
        upgrade_plan:
          type: object
          nullable: true
          description: >-
            The smallest plan that lifts the limit; null when the plan is
            someone else's or no plan lifts it.
          required:
            - plan
            - name
            - monthly_price
            - yearly_price
            - accounts
            - accounts_per_workspace
          properties:
            plan:
              type: string
              description: The plan's key.
            name:
              type: string
              description: The plan's name.
            monthly_price:
              type: integer
            yearly_price:
              type: integer
            accounts:
              type: integer
              description: The social accounts the plan includes.
            accounts_per_workspace:
              type: boolean
              description: True when `accounts` counts per workspace rather than in all.
    Error:
      type: object
      description: >-
        An error answer. Every one has `message`, in plain words; some add an
        `error` code and fields of their own.
      required:
        - message
      properties:
        message:
          type: string
          description: What went wrong and what to do about it.
        error:
          type: string
          description: >-
            A code a few errors add, such as `rate_limited`. See [Handle
            errors](/essentials/error-handling#answers-with-an-error-code).
    ValidationError:
      type: object
      description: '422: the request didn''t pass validation, and nothing changed.'
      required:
        - message
        - errors
      properties:
        message:
          type: string
          description: >-
            The first error and, when there are more, how many: `(and 1 more
            error)`, `(and 2 more errors)`.
        errors:
          type: object
          description: >-
            The messages, by field. A field inside a list is named with dots:
            `accounts.0.id`.
          additionalProperties:
            type: array
            items:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.