跳转至

用户模块

用户自身操作

🔐 用户鉴权

获取自己所在分组

  • 接口名称:获取自己所在分组
  • HTTP 方法:GET
  • 路径/api/user/self/groups
  • 鉴权要求:用户
  • 功能简介:获取当前登录用户可使用的分组信息,包含分组倍率和描述

💡 请求示例:

const response = await fetch('/api/user/self/groups', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "",  
  "data": {  
    "default": {  
      "ratio": 1.0,  
      "desc": "默认分组"  
    },  
    "vip": {  
      "ratio": 0.8,  
      "desc": "VIP分组"  
    },  
    "auto": {  
      "ratio": "自动",  
      "desc": "自动选择最优分组"  
    }  
  }  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "获取分组信息失败"  
}

🧾 字段说明:

data (对象): 用户可用分组信息映射 group.go:25-48

  • 键 (字符串): 分组名称
  • ratio (数字/字符串): 分组倍率,"自动"表示自动选择最优分组
  • desc (字符串): 分组描述

获取个人资料

  • 接口名称:获取个人资料
  • HTTP 方法:GET
  • 路径/api/user/self
  • 鉴权要求:用户
  • 功能简介:获取当前用户的详细信息,包含权限、配额、设置等

💡 请求示例:

const response = await fetch('/api/user/self', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "",  
  "data": {  
    "id": 1,  
    "username": "testuser",  
    "display_name": "Test User",  
    "role": 1,  
    "status": 1,  
    "email": "user@example.com",  
    "group": "default",  
    "quota": 1000000,  
    "used_quota": 50000,  
    "request_count": 100,  
    "aff_code": "ABC123",  
    "aff_count": 5,  
    "aff_quota": 10000,  
    "aff_history_quota": 50000,  
    "inviter_id": 0,  
    "linux_do_id": "",  
    "setting": "{}",  
    "stripe_customer": "",  
    "sidebar_modules": "{\"chat\":{\"enabled\":true}}",  
    "permissions": {  
      "can_view_logs": true,  
      "can_manage_tokens": true  
    }  
  }  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "获取用户信息失败"  
}

🧾 字段说明:

  • id (数字): 用户 ID
  • username (字符串): 用户名
  • display_name (字符串): 显示名称
  • role (数字): 用户角色,1=普通用户,10=管理员,100=Root 用户
  • status (数字): 用户状态,1=正常,2=禁用
  • email (字符串): 邮箱地址
  • group (字符串): 所属分组
  • quota (数字): 总配额
  • used_quota (数字): 已使用配额
  • request_count (数字): 请求次数
  • aff_code (字符串): 推荐码
  • aff_count (数字): 推荐人数
  • aff_quota (数字): 推荐奖励配额
  • aff_history_quota (数字): 历史推荐配额
  • inviter_id (数字): 邀请人 ID
  • linux_do_id (字符串): LinuxDo 账户 ID
  • setting (字符串): 用户设置 JSON 字符串
  • stripe_customer (字符串): Stripe 客户 ID
  • sidebar_modules (字符串): 侧边栏模块配置 JSON 字符串
  • permissions (对象): 用户权限信息

获取模型可见性

  • 接口名称:获取模型可见性
  • HTTP 方法:GET
  • 路径/api/user/models
  • 鉴权要求:用户
  • 功能简介:获取当前用户可访问的 AI 模型列表

💡 请求示例:

const response = await fetch('/api/user/models', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "",  
  "data": [  
    "gpt-3.5-turbo",  
    "gpt-4",  
    "claude-3-sonnet",  
    "claude-3-haiku"  
  ]  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "获取模型列表失败"  
}

🧾 字段说明:

data (数组): 用户可访问的模型名称列表

修改个人资料

  • 接口名称:修改个人资料
  • HTTP 方法:PUT
  • 路径/api/user/self
  • 鉴权要求:用户
  • 功能简介:更新用户个人信息或侧边栏设置

💡 请求示例(更新个人信息):

const response = await fetch('/api/user/self', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },  
  body: JSON.stringify({  
    display_name: "New Display Name",  
    email: "newemail@example.com"  
  })  
});  
const data = await response.json();

💡 请求示例(更新侧边栏设置):

const response = await fetch('/api/user/self', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },  
  body: JSON.stringify({  
    sidebar_modules: JSON.stringify({  
      chat: { enabled: true, playground: true },  
      console: { enabled: true, token: true }  
    })  
  })  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "更新成功"  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "输入不合法"  
}

🧾 字段说明:

  • display_name (字符串): 显示名称,可选
  • email (字符串): 邮箱地址,可选
  • password (字符串): 新密码,可选
  • sidebar_modules (字符串): 侧边栏模块配置 JSON 字符串,可选

注销账号

  • 接口名称:注销账号
  • HTTP 方法:DELETE
  • 路径/api/user/self
  • 鉴权要求:用户
  • 功能简介:删除当前用户账户,Root 用户不可删除

💡 请求示例:

const response = await fetch('/api/user/self', {  
  method: 'DELETE',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": ""  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "不能删除超级管理员账户"  
}

🧾 字段说明:

无请求参数

生成用户级别 Access Token

  • 接口名称:生成用户级别 Access Token
  • HTTP 方法:GET
  • 路径/api/user/token
  • 鉴权要求:用户
  • 功能简介:为当前用户生成新的访问令牌,用于 API 调用

💡 请求示例:

const response = await fetch('/api/user/token', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "",  
  "data": "<YOUR_API_KEY>"  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "生成令牌失败"  
}

🧾 字段说明:

data (字符串): 生成的访问令牌

获取推广码信息

  • 接口名称:获取推广码信息
  • HTTP 方法:GET
  • 路径/api/user/aff
  • 鉴权要求:用户
  • 功能简介:获取或生成用户的推广码,用于邀请新用户注册

💡 请求示例:

const response = await fetch('/api/user/aff', {  
  method: 'GET',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "",  
  "data": "ABC123"  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "获取推广码失败"  
}

🧾 字段说明:

data (字符串): 用户的推广码,如果不存在会自动生成 4 位随机字符串

推广额度转账

  • 接口名称:推广额度转账
  • HTTP 方法:POST
  • 路径/api/user/aff_transfer
  • 鉴权要求:用户
  • 功能简介:将推广奖励额度转换为可用配额

💡 请求示例:

const response = await fetch('/api/user/aff_transfer', {  
  method: 'POST',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },  
  body: JSON.stringify({  
    quota: 50000  
  })  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "划转成功"  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "邀请额度不足!"  
}

🧾 字段说明:

quota (数字): 要转换的额度数量,必须大于等于最小单位额度

更新用户设置

  • 接口名称:更新用户设置
  • HTTP 方法:PUT
  • 路径/api/user/setting
  • 鉴权要求:用户
  • 功能简介:更新用户的个人设置配置

💡 请求示例:

const response = await fetch('/api/user/setting', {  
  method: 'PUT',  
  headers: {  
    'Content-Type': 'application/json',  
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },  
  body: JSON.stringify({  
    theme: "dark",  
    language: "zh-CN",  
    notifications: {  
      email: true,  
      browser: false  
    }  
  })  
});  
const data = await response.json();

✅ 成功响应示例:

{  
  "success": true,  
  "message": "设置更新成功"  
}

❗ 失败响应示例:

{  
  "success": false,  
  "message": "设置格式错误"  
}

🧾 字段说明:

  • 请求体可包含任意用户设置字段,以 JSON 格式提交
  • 具体字段根据前端设置页面的需求而定