关于 modelslab-account-management
ModelsLab Account Management 是通过 Agent Control Plane API 管理 ModelsLab 账户的技能,涵盖身份验证、令牌、个人资料、API 密钥和团队,并支持无浏览器邮件验证。这些能力也可通过其 MCP 服务使用。
主要功能
- 01注册、登录与邮件验证
- 02令牌创建、轮换与撤销
- 03个人资料和密码管理
- 04API 密钥创建与维护
- 05团队成员邀请与管理
适用场景
- 01以无浏览器方式创建并验证账号
- 02轮换 Agent 的访问令牌
- 03为生成端点管理 API 密钥
- 04邀请或移除团队成员
MCP 相关
MCP 服务地址为 https://modelslab.com/mcp/agents,提供账户、令牌、资料、API 密钥和团队管理工具。使用 Bearer 令牌认证。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ modelslab/ skills --skill modelslab-account-management安装后在 Claude Code 中输入/modelslab-account-management确认已加载。
详细介绍
ModelsLab 账户管理
通过 Agent Control Plane API 管理完整的 ModelsLab 账户生命周期——身份验证、令牌、个人资料、API 密钥和团队。
何时使用此技能
- 以编程方式注册或登录 ModelsLab
- 为生成端点创建和管理 API 密钥
- 更新用户个人资料、密码或社交链接
- 管理访问令牌(列出、撤销、切换团队账户)
- 邀请、更新或移除团队成员
- 构建需要初始化账户的 Agent 工作流
身份验证
Agent Control Plane 使用持有者令牌(而非 API 密钥)。部分端点(注册、登录、忘记密码)无需令牌即可使用。
Base URL: https://modelslab.com/api/agents/v1
Authorization: Bearer <agent_access_token>
身份验证:注册与登录
注册
import requests
def signup(email, password, name=None):
"""Create a new ModelsLab account."""
response = requests.post(
"https://modelslab.com/api/agents/v1/auth/signup",
json={
"email": email,
"password": password,
"name": name or ""
}
)
data = response.json()
if "error" in data:
raise Exception(data["error"])
return data["data"] # Contains access_token
# Usage
result = signup("[email protected]", "securepass123", "My Agent")
token = result["access_token"]
print(f"Signed up! Token: {token}")
登录
def login(email, password, token_expiry="1_month"):
"""Log in and get a bearer token.
Args:
token_expiry: "1_week", "1_month" (default), "3_months", "never"
"""
response = requests.post(
"https://modelslab.com/api/agents/v1/auth/login",
json={
"email": email,
"password": password,
"device_name": "my-agent",
"token_expiry": token_expiry
}
)
data = response.json()
if "error" in data:
raise Exception(data["error"])
return data["data"]["access_token"]
# Usage
token = login("[email protected]", "securepass123")
登出
def logout(token):
"""Revoke current token."""
requests.post(
"https://modelslab.com/api/agents/v1/auth/logout",
headers={"Authorization": f"Bearer {token}"}
)
def logout_all(token):
"""Revoke all tokens for this account."""
requests.post(
"https://modelslab.com/api/agents/v1/auth/logout-all",
headers={"Authorization": f"Bearer {token}"}
)
验证电子邮件(无头模式)
注册后,用户会通过电子邮件收到 verification_code。无需浏览器即可完成验证:
def verify_email(verification_code):
"""Verify email with the code from the verification email.
Returns an access_token and api_key — no browser required.
"""
response = requests.post(
"https://modelslab.com/api/agents/v1/auth/verify-email",
json={"verification_code": verification_code}
)
data = response.json()
if "error" in data:
raise Exception(data["error"])
return data["data"]
# Usage — complete headless signup flow
result = verify_email("the_code_from_email")
token = result["access_token"]
api_key = result["api_key"]
print(f"Verified! Token: {token}, API Key: {api_key}")
刷新令牌
无需重新进行身份验证即可轮换当前持有者令牌:
def refresh_token(token, token_expiry="1_month"):
"""Refresh/rotate the current access token.
The old token is revoked and a new one is issued.
Args:
token_expiry: "1_week", "1_month" (default), "3_months", "never"
"""
response = requests.post(
"https://modelslab.com/api/agents/v1/auth/refresh",
headers={"Authorization": f"Bearer {token}"},
json={"token_expiry": token_expiry}
)
data = response.json()
if "error" in data:
raise Exception(data["error"])
return data["data"]["access_token"]
# Usage — rotate token before it expires
new_token = refresh_token(old_token, token_expiry="1_month")
重置密码
def forgot_password(email):
"""Request a password reset email."""
requests.post(
"https://modelslab.com/api/agents/v1/auth/forgot-password",
json={"email": email}
)
def reset_password(email, token, new_password):
"""Reset password using the reset token from email."""
requests.post(
"https://modelslab.com/api/agents/v1/auth/reset-password",
json={
"email": email,
"token": token,
"password": new_password,
"password_confirmation": new_password
}
)
令牌管理
def make_headers(token):
return {"Authorization": f"Bearer {token}"}
def list_tokens(token):
"""List all active tokens."""
resp = requests.get(
"https://modelslab.com/api/agents/v1/auth/tokens",
headers=make_headers(token)
)
return resp.json()["data"]
def revoke_token(token, token_id):
"""Revoke a specific token by ID."""
requests.delete(
f"https://modelslab.com/api/agents/v1/auth/tokens/{token_id}",
headers=make_headers(token)
)
def revoke_other_tokens(token):
"""Revoke all tokens except the current one."""
requests.post(
"https://modelslab.com/api/agents/v1/auth/tokens/revoke-others",
headers=make_headers(token)
)
def switch_account(token, team_username):
"""Switch to a team account context. Returns new token."""
resp = requests.post(
"https://modelslab.com/api/agents/v1/auth/switch-account",
headers=make_headers(token),
json={"account_username": team_username}
)
return resp.json()["data"]["access_token"]
个人资料管理
获取个人资料
def get_profile(token):
"""Get the authenticated user's profile."""
resp = requests.get(
"https://modelslab.com/api/agents/v1/me",
headers=make_headers(token)
)
return resp.json()["data"]
# Usage
profile = get_profile(token)
print(f"Name: {profile['name']}, Email: {profile['email']}")
print(f"Wallet: ${profile.get('wallet_balance', 0)}")
更新个人资料
def update_profile(token, name=None, username=None, about_me=None):
"""Update profile fields."""
payload = {}
if name: payload["name"] = name
if username: payload["username"] = username
if about_me: payload["about_me"] = about_me
resp = requests.patch(
"https://modelslab.com/api/agents/v1/me",
headers=make_headers(token),
json=payload
)
return resp.json()["data"]
def update_password(token, current_password, new_password):
"""Change account password."""
requests.patch(
"https://modelslab.com/api/agents/v1/me/password",
headers=make_headers(token),
json={
"current_password": current_password,
"password": new_password,
"password_confirmation": new_password
}
)
def update_socials(token, github=None, twitter=None, discord=None):
"""Update social media links."""
payload = {}
if github: payload["github"] = github
if twitter: payload["twitter"] = twitter
if discord: payload["discord"] = discord
requests.patch(
"https://modelslab.com/api/agents/v1/me/socials",
headers=make_headers(token),
json=payload
)
def update_preferences(token, nsfw_content=None, wallet_notification_enabled=None):
"""Update account preferences."""
payload = {}
if nsfw_content is not None: payload["nsfw_content"] = nsfw_content
if wallet_notification_enabled is not None:
payload["wallet_notification_enabled"] = wallet_notification_enabled
requests.patch(
"https://modelslab.com/api/agents/v1/me/preferences",
headers=make_headers(token),
json=payload
)
API 密钥管理
API 密钥用于生成端点(/api/v6、/api/v7、/api/v8)。
列出 API 密钥
def list_api_keys(token):
"""List all API keys."""
resp = requests.get(
"https://modelslab.com/api/agents/v1/api-keys",
headers=make_headers(token)
)
return resp.json()["data"]
创建 API 密钥
def create_api_key(token, name, notes=None):
"""Create a new API key for generation endpoints.
Returns the full key — store it securely, it won't be shown again.
"""
payload = {"name": name}
if notes: payload["notes"] = notes
resp = requests.post(
"https://modelslab.com/api/agents/v1/api-keys",
headers=make_headers(token),
json=payload
)
return resp.json()["data"]
# Usage
key_data = create_api_key(token, "production-key", notes="Used by CI/CD")
api_key = key_data["key"]
print(f"API Key: {api_key}")
获取、更新、删除 API 密钥
def get_api_key(token, key_id):
"""Get details of a specific API key."""
resp = requests.get(
f"https://modelslab.com/api/agents/v1/api-keys/{key_id}",
headers=make_headers(token)
)
return resp.json()["data"]
def update_api_key(token, key_id, name=None, notes=None):
"""Update an API key's name or notes."""
payload = {}
if name: payload["name"] = name
if notes: payload["notes"] = notes
resp = requests.put(
f"https://modelslab.com/api/agents/v1/api-keys/{key_id}",
headers=make_headers(token),
json=payload
)
return resp.json()["data"]
def delete_api_key(token, key_id):
"""Delete an API key."""
requests.delete(
f"https://modelslab.com/api/agents/v1/api-keys/{key_id}",
headers=make_headers(token)
)
团队管理
列出团队成员
def list_team_members(token):
"""List all team members and pending invites."""
resp = requests.get(
"https://modelslab.com/api/agents/v1/teams",
headers=make_headers(token)
)
return resp.json()["data"]
邀请团队成员
def invite_team_member(token, email):
"""Send a team invite to an email address."""
resp = requests.post(
"https://modelslab.com/api/agents/v1/teams",
headers=make_headers(token),
json={"email": email}
)
return resp.json()["data"]
# Usage
invite_team_member(token, "[email protected]")
管理成员
def get_team_member(token, member_id):
"""Get details of a team member."""
resp = requests.get(
f"https://modelslab.com/api/agents/v1/teams/{member_id}",
headers=make_headers(token)
)
return resp.json()["data"]
def update_team_member(token, member_id, role=None, permissions=None):
"""Update a team member's role or permissions."""
payload = {}
if role: payload["role"] = role
if permissions: payload["permissions"] = permissions
resp = requests.put(
f"https://modelslab.com/api/agents/v1/teams/{member_id}",
headers=make_headers(token),
json=payload
)
return resp.json()["data"]
def remove_team_member(token, member_id):
"""Remove a member from the team."""
requests.delete(
f"https://modelslab.com/api/agents/v1/teams/{member_id}",
headers=make_headers(token)
)
def resend_invite(token, member_id):
"""Resend a pending team invite."""
requests.post(
f"https://modelslab.com/api/agents/v1/teams/{member_id}/resend-invite",
headers=make_headers(token)
)
def accept_invite(token, invite_id):
"""Accept a team invitation."""
requests.post(
f"https://modelslab.com/api/agents/v1/teams/invitations/{invite_id}/accept",
headers=make_headers(token)
)
完整的 Agent 初始化示例
import requests
class ModelsLabAgent:
"""Bootstrap a ModelsLab account for an AI agent."""
BASE = "https://modelslab.com/api/agents/v1"
def __init__(self):
self.token = None
self.api_key = None
def _headers(self):
return {"Authorization": f"Bearer {self.token}"}
def login(self, email, password):
"""Step 1: Authenticate."""
resp = requests.post(f"{self.BASE}/auth/login", json={
"email": email,
"password": password,
"token_expiry": "1_month"
})
self.token = resp.json()["data"]["access_token"]
return self
def get_or_create_api_key(self, name="agent-key"):
"""Step 2: Get existing key or create one."""
keys = requests.get(
f"{self.BASE}/api-keys",
headers=self._headers()
).json()["data"]
for key in keys:
if key["name"] == name:
self.api_key = key["key"]
return self.api_key
new_key = requests.post(
f"{self.BASE}/api-keys",
headers=self._headers(),
json={"name": name}
).json()["data"]
self.api_key = new_key["key"]
return self.api_key
def check_ready(self):
"""Step 3: Verify account is ready for generation."""
profile = requests.get(
f"{self.BASE}/me",
headers=self._headers()
).json()["data"]
print(f"Account: {profile['name']} ({profile['email']})")
print(f"API Key: {self.api_key[:8]}...")
return True
# Usage
agent = ModelsLabAgent()
agent.login("[email protected]", "password")
agent.get_or_create_api_key("production")
agent.check_ready()
# Now use agent.api_key with generation endpoints
无头 Agent 流程(无需浏览器)
面向需要在不进行任何浏览器交互的情况下完成注册、验证、添加付款方式、订阅和生成内容的 Agent 的完整流程。关于三种付款路径(无头模式、设置意图、人工协助),请参阅 modelslab-billing-subscriptions。
import requests
BASE = "https://modelslab.com/api/agents/v1"
# Fetch Stripe publishable key dynamically
config_resp = requests.get(f"{BASE}/billing/stripe-config",
headers={"Authorization": f"Bearer {token}"})
STRIPE_PK = config_resp.json()["publishable_key"]
# 1. Sign up
signup_resp = requests.post(f"{BASE}/auth/signup", json={
"email": "[email protected]",
"password": "securepass123",
"name": "My Agent"
})
# -> User receives verification_code in email
# 2. Verify email with code from email (no browser needed)
verify_resp = requests.post(f"{BASE}/auth/verify-email", json={
"verification_code": "the_code_from_email"
})
token = verify_resp.json()["data"]["access_token"]
api_key = verify_resp.json()["data"]["api_key"]
hdrs = {"Authorization": f"Bearer {token}"}
# 3a. Option A: Headless card tokenization via Stripe API (recommended)
# Or fetch key dynamically: GET /billing/stripe-config
pm_resp = requests.post(
"https://api.stripe.com/v1/payment_methods",
auth=(STRIPE_PK, ""),
data={
"type": "card",
"card[number]": "4242424242424242",
"card[exp_month]": 12,
"card[exp_year]": 2027,
"card[cvc]": "123",
}
)
pm_id = pm_resp.json()["id"]
# 3b. Option B: Setup Intent flow (save card for future use)
# setup_resp = requests.post(f"{BASE}/billing/setup-intent", headers=hdrs)
# -> Confirm with Stripe API, then use the resulting pm_id
# 3c. Option C: Human-assisted payment link
# link = requests.post(f"{BASE}/billing/payment-link", headers=hdrs, json={
# "purpose": "subscribe", "plan_id": 123
# }).json()["data"]
# -> Forward link["payment_url"] to human, then confirm-checkout
# 4. Attach the payment method
requests.post(f"{BASE}/billing/payment-methods", headers=hdrs, json={
"payment_method_id": pm_id,
"make_default": True
})
# 5. Subscribe headlessly with payment_method_id (no Checkout redirect)
sub_resp = requests.post(f"{BASE}/subscriptions", headers=hdrs, json={
"plan_id": 123,
"payment_method_id": pm_id
})
# 6. Generate content using existing APIs with the api_key from step 2
gen_resp = requests.post("https://modelslab.com/api/v6/images/text2img", json={
"key": api_key,
"model_id": "flux-dev",
"prompt": "A sunset over mountains",
"width": 1024,
"height": 1024
})
MCP 服务访问
通过 Agent Control Plane MCP 服务也可使用这些功能:
- URL:
https://modelslab.com/mcp/agents - 身份验证:
Authorization: Bearer <token> - 工具:
agent-auth、agent-tokens、agent-profile、agent-api-keys、agent-teams
请参阅:https://docs.modelslab.com/mcp-web-api/agent-control-plane
API 端点参考
| 方法 | 端点 | 说明 |
|---|---|---|
| POST | /auth/signup | 创建账户 |
| POST | /auth/login | 获取持有者令牌 |
| POST | /auth/verify-email | 使用验证码验证电子邮件(无头模式) |
| POST | /auth/refresh | 刷新/轮换访问令牌 |
| POST | /auth/logout | 撤销当前令牌 |
| POST | /auth/logout-all | 撤销所有令牌 |
| POST | /auth/forgot-password | 请求发送重置邮件 |
| POST | /auth/reset-password | 使用令牌重置密码 |
| POST | /auth/resend-verification | 重新发送验证邮件 |
| GET | /auth/tokens | 列出有效令牌 |
| DELETE | /auth/tokens/{id} | 撤销指定令牌 |
| POST | /auth/tokens/revoke-others | 撤销其他令牌 |
| POST | /auth/switch-account | 切换团队上下文 |
| GET | /me | 获取个人资料 |
| PATCH | /me | 更新个人资料 |
| PATCH | /me/password | 修改密码 |
| PATCH | /me/socials | 更新社交链接 |
| PATCH | /me/preferences | 更新偏好设置 |
| GET | /api-keys | 列出 API 密钥 |
| POST | /api-keys | 创建 API 密钥 |
| GET | /api-keys/{id} | 获取 API 密钥 |
| PUT | /api-keys/{id} | 更新 API 密钥 |
| DELETE | /api-keys/{id} | 删除 API 密钥 |
| GET | /teams | 列出团队成员 |
| POST | /teams | 邀请成员 |
| GET | /teams/{id} | 获取成员详情 |
| PUT | /teams/{id} | 更新成员 |
| DELETE | /teams/{id} | 移除成员 |
| POST | /teams/{id}/resend-invite | 重新发送邀请 |
| POST | /teams/invitations/{id}/accept | 接受邀请 |
最佳实践
1. 安全存储令牌
import os
# Use environment variables, not hardcoded values
token = os.getenv("MODELSLAB_AGENT_TOKEN")
2. 合理利用令牌有效期
# Short-lived for CI/CD
login(email, password, token_expiry="1_week")
# Long-lived for persistent agents
login(email, password, token_expiry="never")
3. 创建描述性 API 密钥
create_api_key(token, "staging-backend", notes="Used by staging environment")
create_api_key(token, "ci-tests", notes="Used by GitHub Actions")
4. 清理旧令牌
# Revoke all other tokens when rotating
revoke_other_tokens(token)
资源
- API 文档:https://docs.modelslab.com/agents-api/overview
- MCP 服务:https://docs.modelslab.com/mcp-web-api/agent-control-plane
- 仪表板:https://modelslab.com/dashboard
- Discord:https://discord.gg/modelslab
相关技能
modelslab-billing-subscriptions- 账单、钱包和订阅管理modelslab-model-discovery- 搜索模型并查看使用情况分析modelslab-training- 模型训练和微调modelslab-servers- 部署专用 GPU 服务modelslab-image-generation- 使用 API 密钥生成图像
评论
支持 Markdown