unkey

关于 Unkey 的专家说明,Unkey 是一个开源的 API 密钥管理平台。适用于帮助开发者创建、验证与管理 API 密钥,并提供内置速率限制、使用量追踪、临时密钥、密钥轮换和基于密钥的权限控制,为开发者平台、SaaS API 和内部服务提供 API 认证层的资料与建议。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "unkey":https://skillpi.com/zh/skills/deepskill-aba9b17e42679a0968aa7b0257879e5ef584ac0484d1f690abd2bb075408341c。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

关于 Unkey 的专家说明,Unkey 是一个开源的 API 密钥管理平台。适用于帮助开发者创建、验证与管理 API 密钥,并提供内置速率限制、使用量追踪、临时密钥、密钥轮换和基于密钥的权限控制,为开发者平台、SaaS API 和内部服务提供 API 认证层的资料与建议。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: unkey
description: >-
  You are an expert in Unkey, the open-source API key management platform.
  You help developers create, validate, and manage API keys with built-in rate
  limiting, usage tracking, temporary keys, key rotation, and per-key
  permissions — providing the complete API authentication layer for developer
  platforms, SaaS APIs, and internal services without building custom key
  infrastructure.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Backend Development
  tags:
    - api-keys
    - authentication
    - rate-limiting
    - usage
    - developer-platform

Unkey — API Key Management

You are an expert in Unkey, the open-source API key management platform. You help developers create, validate, and manage API keys with built-in rate limiting, usage tracking, temporary keys, key rotation, and per-key permissions — providing the complete API authentication layer for developer platforms, SaaS APIs, and internal services without building custom key infrastructure.

Core Capabilities

Key Management

import { Unkey } from "@unkey/api";

const unkey = new Unkey({ rootKey: process.env.UNKEY_ROOT_KEY! });

// Create API key for a customer
const { result } = await unkey.keys.create({
  apiId: process.env.UNKEY_API_ID!,
  prefix: "sk_live",                       // Key prefix for identification
  name: "Acme Corp Production Key",
  ownerId: "customer-42",                  // Link to your user
  meta: {                                  // Custom metadata
    plan: "pro",
    team: "engineering",
  },
  roles: ["api.read", "api.write"],        // RBAC permissions
  ratelimit: {
    type: "fast",
    limit: 100,                            // 100 requests
    duration: 60000,                       // Per minute
  },
  remaining: 10000,                        // Total usage limit (optional)
  expires: Date.now() + 30 * 24 * 60 * 60 * 1000,  // 30 days (optional)
});

console.log(result.key);                   // sk_live_abc123... (show once!)
console.log(result.keyId);                 // key_xxx (for management)

Key Verification (in your API)

import { verifyKey } from "@unkey/api";

// Middleware — verify API key on every request
async function authMiddleware(req: Request) {
  const key = req.headers.get("Authorization")?.replace("Bearer ", "");
  if (!key) return new Response("Missing API key", { status: 401 });

  const { result, error } = await verifyKey({
    key,
    apiId: process.env.UNKEY_API_ID!,
  });

  if (error || !result.valid) {
    return new Response(JSON.stringify({
      error: "Invalid API key",
      code: result?.code,                  // "NOT_FOUND" | "RATE_LIMITED" | "USAGE_EXCEEDED" | "EXPIRED"
    }), { status: result?.code === "RATE_LIMITED" ? 429 : 403 });
  }

  // Key is valid — access metadata
  const { ownerId, meta, roles, remaining, ratelimit } = result;
  console.log(`Customer: ${ownerId}, Plan: ${meta.plan}, Remaining: ${remaining}`);

  // Check permissions
  if (!roles.includes("api.write") && req.method !== "GET") {
    return new Response("Insufficient permissions", { status: 403 });
  }

  // Rate limit info in response headers
  return {
    ownerId,
    meta,
    headers: {
      "X-RateLimit-Limit": String(ratelimit?.limit),
      "X-RateLimit-Remaining": String(ratelimit?.remaining),
      "X-RateLimit-Reset": String(ratelimit?.reset),
    },
  };
}

Key Lifecycle

// Update key (change limits, roles)
await unkey.keys.update({
  keyId: "key_xxx",
  ratelimit: { type: "fast", limit: 500, duration: 60000 },  // Upgrade limit
  roles: ["api.read", "api.write", "api.admin"],
  meta: { plan: "enterprise" },
});

// Revoke key
await unkey.keys.delete({ keyId: "key_xxx" });

// List keys for a customer
const { result: keys } = await unkey.apis.listKeys({
  apiId: process.env.UNKEY_API_ID!,
  ownerId: "customer-42",
});

// Usage analytics
const { result: verifications } = await unkey.keys.getVerifications({
  keyId: "key_xxx",
  start: Date.now() - 7 * 24 * 60 * 60 * 1000,  // Last 7 days
  end: Date.now(),
  granularity: "day",
});

Installation

npm install @unkey/api

Best Practices

  1. Prefix keys — Use sk_live_, sk_test_ prefixes; identifies key type at a glance
  2. Rate limiting built-in — Set per-key rate limits at creation; Unkey enforces at verify time
  3. Usage limits — Set remaining for prepaid/quota models; key auto-invalidates when exhausted
  4. RBAC roles — Assign roles to keys; check in your middleware; scope access per endpoint
  5. Key rotation — Create new key, update client, revoke old; zero-downtime rotation
  6. Metadata — Store plan, team, environment in meta; use for analytics and feature flags
  7. Expiring keys — Set expires for trial keys, temporary access; auto-expire without cron
  8. Self-hostable — Run Unkey on your own infrastructure for data sovereignty; open-source

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供完整的 API 密钥管理解决方案,涵盖创建、验证、权限控制、速率限制等核心功能
  • 面向开发者平台、SaaS API 和内部服务,解决高频刚需问题
  • 包含端到端代码示例和最佳实践指导
触发精准95/100

亮点

  • description 明确描述 Unkey 专家角色及核心能力
  • 触发词精准覆盖 API 密钥管理的多种场景
  • 边界清晰,无歧义
结构规范95/100

亮点

  • 结构清晰,分区明确(Core Capabilities、Installation、Best Practices)
  • 包含完整 TypeScript 代码示例
  • frontmatter 完整,单文件长度符合规范
执行可靠90/100

亮点

  • 工具来源明确(@unkey/api)
  • 参数使用正确,包含完善的错误处理机制
  • 覆盖主要异常场景(无效密钥、速率限制、权限不足)
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 137 行
  • 账号、密钥或授权

    使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。

    主文档提及 · 第 4, 24, 26, 37, 66 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。