":{"code":"","message":"Invalid Token (request id: 2026031815524720261752387BZ2g...

2026年03月18日 15:53 processing

错误信息

GET /models: 401 {"error":{"code":"","message":"Invalid Token (request id: 2026031815524720261752387BZ2giN)","type":"rix_api_error"}}

AI 解决方案

报错分析报告

1.错误翻译


原文:Invalid Token (request id: 2026031815524720261752387BZ2giN)
译文:无效令牌(请求ID:2026031815524720261752387BZ2giN)

2.原因分析


  • 根本原因:请求携带的认证令牌(Token)无效或已过期。

  • 发生位置:发送GET /models API请求时,认证环节失败。

  • 上下文:API要求有效令牌但未通过校验(令牌可能拼写错误、过期或未授权)。
  • 3. 解决方案


    替换无效令牌为有效且未过期的令牌,并在请求头中正确携带:

    #### Bash示例(curl)

    # 1. 替换为你的有效令牌
    VALID_TOKEN="sk-your_valid_dmxapi_token"
    
    # 2. 带令牌请求模型列表
    curl -H "Authorization: Bearer $VALID_TOKEN" \
         https://api.dmxapi.com/models
    

    #### Python示例(requests)

    import requests
    
    url = "https://api.dmxapi.com/models"
    headers = {"Authorization": "Bearer YOUR_VALID_TOKEN"}  # 替换为有效令牌
    
    response = requests.get(url, headers=headers)
    print(response.json())
    

    4. 预防措施


  • 令牌管理:使用环境变量(如.env文件+python-dotenv)存储令牌,避免硬编码;定期轮换令牌。

  • 前置校验:请求前用工具(如Postman、curl)验证令牌有效性,或通过API的/auth/verify端点预检查。
  • 推荐工具dotenv(环境变量管理)、Postman(API调试)。