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

# Exchange OAuth code

> Exchanges an OAuth authorization code for a connected social account. Use this when
you handle the OAuth callback on your own server (proxy flow). For a single account
the response is a flat ConnectAccountResponse (HTTP 201). When a single OAuth flow
connects multiple accounts (e.g. Facebook Pages) the response is OAuthCallbackResponse.



## OpenAPI

````yaml /api-reference/openapi.json post /oauth/exchange
openapi: 3.0.0
info:
  description: >-
    Unified social media inbox API. Read and respond to comments, DMs, reviews,
    and mentions across Instagram, Facebook, Threads, Google Business Profile,
    TikTok, LinkedIn, and YouTube through a single REST API. X/Twitter and
    Trustpilot coming soon.
  title: SocialAPI.AI
  contact:
    name: SocialAPI.AI Support
    email: support@social-api.ai
  license:
    name: MIT
  version: '1.0'
servers:
  - url: https://api.social-api.ai/v1
security: []
paths:
  /oauth/exchange:
    post:
      tags:
        - Accounts
      summary: Exchange OAuth code
      description: >-
        Exchanges an OAuth authorization code for a connected social account.
        Use this when

        you handle the OAuth callback on your own server (proxy flow). For a
        single account

        the response is a flat ConnectAccountResponse (HTTP 201). When a single
        OAuth flow

        connects multiple accounts (e.g. Facebook Pages) the response is
        OAuthCallbackResponse.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/api_endpoints.ExchangeRequest'
        description: Platform, code, and metadata (redirect_uri + state required)
        required: true
      responses:
        '201':
          description: Single account connected
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_endpoints.ConnectAccountResponse'
        '400':
          description: Missing or invalid fields
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_endpoints.ErrorResponse'
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_endpoints.ErrorResponse'
        '403':
          description: >-
            Plan limit reached (billing.platform_not_available or
            billing.brands_limit)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_endpoints.ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    api_endpoints.ExchangeRequest:
      type: object
      properties:
        code:
          description: Code is the authorization code received from the platform callback.
          type: string
          example: AQDtbPB9X...
        metadata:
          description: Metadata must include redirect_uri and state for CSRF validation.
          type: object
          additionalProperties: {}
        platform:
          description: >-
            Platform identifies the social platform (must match the connect
            call).
          type: string
          example: instagram
    api_endpoints.ConnectAccountResponse:
      type: object
      properties:
        account_id:
          type: string
          example: acc_01HZ9X3Q4R5M6N7P8V2K0W1J
        display_name:
          type: string
          example: Acme Corp
        platform:
          type: string
          example: instagram
        username:
          type: string
          example: acmecorp
    api_endpoints.ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/api_endpoints.ErrorBody'
    api_endpoints.ErrorBody:
      type: object
      properties:
        code:
          type: string
          example: resource.not_found
        message:
          type: string
          example: Account not found
        meta:
          type: object
          additionalProperties: {}
  securitySchemes:
    BearerAuth:
      description: >-
        Prefix your API key with "Bearer ". Example: `Authorization: Bearer
        sapi_key_...`
      type: apiKey
      name: Authorization
      in: header

````