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

# Exchange a token

> Exchanges an identity provider's token for a short-lived Baseten access token.

> [!NOTE]
>
> [Workload identity federation](https://docs.baseten.co/organization/workload-identity.md) is in **Private Preview**.


## OpenAPI

````yaml post /v1/auth/token
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/auth/token:
    post:
      summary: Exchanges an identity provider's JWT for an access token
      description: >-
        Exchanges a JWT from your identity provider for a short-lived Baseten
        access token, as described in RFC 8693. Send no API key: the JWT is the
        credential. Name the trust rule to check the JWT against as the
        `audience`, and send the access token as `Authorization: Bearer` on
        later requests. Errors follow RFC 6749 section 5.2: a 400 response with
        an `error` of `invalid_request`, `unsupported_grant_type`, or
        `invalid_grant`. A well-formed request that is refused always returns
        `invalid_grant`, whatever the reason.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenExchangeRequestV1'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/TokenExchangeRequestV1'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenExchangeResponseV1'
      security: []
components:
  schemas:
    TokenExchangeRequestV1:
      description: >-
        An RFC 8693 token exchange request naming the trust rule to check as its
        audience.
      properties:
        grant_type:
          description: Always `urn:ietf:params:oauth:grant-type:token-exchange`
          examples:
            - urn:ietf:params:oauth:grant-type:token-exchange
          title: Grant Type
          type: string
        subject_token:
          description: The identity provider's JWT
          examples:
            - <identity provider JWT>
          maxLength: 16384
          title: Subject Token
          type: string
        subject_token_type:
          description: >-
            `urn:ietf:params:oauth:token-type:jwt` or
            `urn:ietf:params:oauth:token-type:id_token`
          examples:
            - urn:ietf:params:oauth:token-type:jwt
          title: Subject Token Type
          type: string
        audience:
          description: ID of the trust rule to check the JWT against
          examples:
            - abcd1234
          maxLength: 64
          title: Audience
          type: string
        requested_token_type:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Optional; only `urn:ietf:params:oauth:token-type:access_token` is
            issued
          title: Requested Token Type
        access_token_lifetime_seconds:
          anyOf:
            - minimum: 1
              type: integer
            - type: 'null'
          default: null
          description: >-
            Lifetime of the access token, in seconds. At most the rule's
            maximum.
          title: Access Token Lifetime Seconds
      required:
        - grant_type
        - subject_token
        - subject_token_type
        - audience
      title: TokenExchangeRequestV1
      type: object
    TokenExchangeResponseV1:
      properties:
        access_token:
          description: 'Send as `Authorization: Bearer`'
          title: Access Token
          type: string
        issued_token_type:
          description: Always `urn:ietf:params:oauth:token-type:access_token`
          title: Issued Token Type
          type: string
        token_type:
          description: Always `Bearer`
          title: Token Type
          type: string
        expires_in:
          description: Seconds until the access token expires
          title: Expires In
          type: integer
      required:
        - access_token
        - issued_token_type
        - token_type
        - expires_in
      title: TokenExchangeResponseV1
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````