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

# Exchange a code or refresh a token

> Exchanges an authorization code (with its PKCE verifier) for an access token and a refresh token, or rotates a refresh token.



## OpenAPI

````yaml /openapi.public.json post /oauth/token
openapi: 3.0.3
info:
  description: >-
    The endpoints a client outside xcale calls to connect to the xcale MCP:
    discovery, client registration, authorization, the token exchange and the
    MCP endpoint.
  title: xcale MCP
  version: 1.0.0
servers:
  - url: https://api.xcale.app
security: []
paths:
  /oauth/token:
    post:
      summary: Exchange a code or refresh a token
      description: >-
        Exchanges an authorization code (with its PKCE verifier) for an access
        token and a refresh token, or rotates a refresh token.
      operationId: token
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              description: >-
                Each field is sent once. `authorization_code` needs `code`,
                `redirect_uri` and `code_verifier`; `refresh_token` needs
                `refresh_token`.
              properties:
                client_id:
                  type: string
                code:
                  description: The single-use authorization code.
                  type: string
                code_verifier:
                  description: 'The PKCE verifier: 43 to 128 characters (RFC 7636).'
                  type: string
                grant_type:
                  enum:
                    - authorization_code
                    - refresh_token
                  type: string
                redirect_uri:
                  description: The same `redirect_uri` the authorization used.
                  type: string
                refresh_token:
                  description: The latest refresh token.
                  type: string
                resource:
                  description: The URL of the xcale MCP endpoint, when sent.
                  type: string
                scope:
                  description: Read and ignored.
                  type: string
              required:
                - grant_type
                - client_id
              type: object
        description: >-
          Each field is sent once. `authorization_code` needs `code`,
          `redirect_uri` and `code_verifier`; `refresh_token` needs
          `refresh_token`.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  access_token:
                    description: 'Sent to the MCP endpoint as `Authorization: Bearer`.'
                    type: string
                  expires_in:
                    description: 'Seconds: always 900.'
                    type: integer
                  refresh_token:
                    type: string
                  token_type:
                    enum:
                      - Bearer
                    type: string
                required:
                  - access_token
                  - token_type
                  - expires_in
                  - refresh_token
                type: object
          description: >-
            The access token, valid for 15 minutes, and a new refresh token. A
            refresh token is used once: keep the latest.
          headers:
            Cache-Control:
              description: 'Always `no-store`: the answer is never cached.'
              schema:
                type: string
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    enum:
                      - invalid_request
                      - unsupported_grant_type
                      - invalid_grant
                      - invalid_target
                    type: string
                  error_description:
                    description: A short English explanation for a developer.
                    type: string
                required:
                  - error
                type: object
          description: The request cannot be honoured.
          headers:
            Cache-Control:
              description: 'Always `no-store`: the answer is never cached.'
              schema:
                type: string
        '401':
          content:
            application/json:
              schema:
                properties:
                  error:
                    enum:
                      - invalid_client
                    type: string
                  error_description:
                    description: A short English explanation for a developer.
                    type: string
                required:
                  - error
                type: object
          description: 'The client is unknown or has expired: register again.'
          headers:
            Cache-Control:
              description: 'Always `no-store`: the answer is never cached.'
              schema:
                type: string
        '429':
          content:
            application/json:
              schema:
                properties:
                  error:
                    enum:
                      - temporarily_unavailable
                    type: string
                  error_description:
                    description: A short English explanation for a developer.
                    type: string
                required:
                  - error
                type: object
          description: Too many token requests. Wait `Retry-After` seconds.
          headers:
            Cache-Control:
              description: 'Always `no-store`: the answer is never cached.'
              schema:
                type: string
            Retry-After:
              description: Seconds to wait before the next call.
              schema:
                type: string
        '503':
          content:
            application/json:
              schema:
                properties:
                  error:
                    enum:
                      - temporarily_unavailable
                    type: string
                  error_description:
                    enum:
                      - connector_disabled
                    type: string
                required:
                  - error
                type: object
          description: The xcale MCP is not enabled on this deployment. Try again later.

````

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