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

# 生成访问令牌

> 使用凭证的 `client_id` 和 `client_secret` 换取短期有效的访问令牌。在其余请求中，通过 `Authorization: Bearer <access_token>` 请求头发送返回的令牌。

令牌在 **300 秒（5 分钟）** 后过期——过期后请重新生成；不提供 refresh token。



## OpenAPI

````yaml openapi.cn.json POST /auth
openapi: 3.0.0
info:
  title: Brazil Pix API
  description: Brazil Pix Payment API documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://api.brazilpix.com/v2
security: []
paths:
  /auth:
    post:
      tags:
        - Autenticação
      summary: 生成访问令牌
      description: >-
        使用凭证的 `client_id` 和 `client_secret` 换取短期有效的访问令牌。在其余请求中，通过
        `Authorization: Bearer <access_token>` 请求头发送返回的令牌。


        令牌在 **300 秒（5 分钟）** 后过期——过期后请重新生成；不提供 refresh token。
      operationId: ExternalAuthController_authenticate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                client_id:
                  type: string
                  description: 凭证标识符（mp_live_* 为生产环境，mp_test_* 为沙箱环境）
                  example: mp_live_0123456789abcdef01234567
                client_secret:
                  type: string
                  description: 凭证的 secret（仅在创建时显示一次）
              required:
                - client_id
                - client_secret
      responses:
        '200':
          description: 令牌生成成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    description: 用于 Authorization 请求头的 JWT 令牌
                    example: eyJhbGciOiJSUzI1NiIs...
                  token_type:
                    type: string
                    example: Bearer
                  expires_in:
                    type: integer
                    description: 令牌有效期（秒）
                    example: 300
                required:
                  - access_token
                  - token_type
                  - expires_in
        '400':
          description: 缺少 client_id 或 client_secret
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
                example:
                  error: Bad Request
                  message: client_id and client_secret are required
        '401':
          description: 凭证无效、已吊销或 secret 不正确
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
                example:
                  error: Unauthorized
                  message: Invalid credentials
      security: []

````

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