@aws/token-generator-for-aws-external-anthropic

中文文档
1.0.0发布于 2026/05/08Apache-2.0TypeScriptCommonJS近 30 天下载 26.3万

A lightweight library for generating short-term bearer tokens for AWS External Anthropic API authentication

原始使用文档
文档目录13 节
  1. Installation
  2. Quick Start
  3. Usage 1 — Using Default Credentials and Region
  4. Usage 2 — Using Custom Configuration
  5. Usage 3 — Using Static One-Shot
  6. API Reference
  7. Token Format
  8. Requirements
  9. Security Considerations
  10. Development
  11. Contributing
  12. License
  13. Changelog

Token Generator for AWS External Anthropic (JavaScript/TypeScript)

A lightweight library for generating short-term bearer tokens for AWS External Anthropic API authentication.

Installation

npm install @aws/token-generator-for-aws-external-anthropic

Quick Start

Token duration can be customized (1 second to 12 hours). The actual token lifetime will be: min(specified duration, credentials expiry, 12 hours). Default is 12 hours.

Usage 1 — Using Default Credentials and Region

import { getTokenProvider } from "@aws/token-generator-for-aws-external-anthropic";

// Create a token provider that uses default credentials and region providers.
const provideToken = getTokenProvider();

async function example() {
  const token = await provideToken();

  // Use the token for API calls. The token has a default expiration of 12 hour.
  // If the expiresInSeconds parameter is specified during token creation, the 
  // expiration can be configured up to a maximum of 12 hours. However, the actual 
  // token validity period will always be the minimum of the requested expiration 
  // time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}

Usage 2 — Using Custom Configuration

This example uses STS Assume Role. You can use any supported credentials provider.

import { getTokenProvider } from "@aws/token-generator-for-aws-external-anthropic";
import { fromTemporaryCredentials } from "@aws-sdk/credential-providers";

const provideToken = getTokenProvider({
  credentials: fromTemporaryCredentials({
    params: {
      RoleArn: "arn:aws:iam::123456789012:role/MyRole",
    },
  }),
  region: "us-east-1",
  expiresInSeconds: 3600,
});

async function example() {
  const token = await provideToken();
  console.log(`Bearer Token: ${token}`);
}

Usage 3 — Using Static One-Shot

Pass credentials, region, and expiry directly. No instance needed.

import { getToken } from "@aws/token-generator-for-aws-external-anthropic";

async function example() {
  const token = await getToken({
    credentials: {
      accessKeyId: "YOUR_ACCESS_KEY_ID",
      secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
      sessionToken: "YOUR_SESSION_TOKEN",
    },
    region: "us-east-1",
    expiresInSeconds: 7200,
  });

  // Use the token for API calls. The token has an expiration of 2 hour. However, the actual token validity period
  // will always be the minimum of the requested expiration time and the AWS credentials' expiry time
  console.log(`Bearer Token: ${token}`);
}

API Reference

Token Format

The generated token has the format:

aws-external-anthropic-api-key-<base64-encoded-payload>

The payload is a Base64-encoded SigV4 presigned URL scoped to the aws-external-anthropic service. The token can be decoded for debugging purposes but should be treated as an opaque string in production.

Requirements

  • Node.js: 16.0.0 or later
  • TypeScript: 4.7.0 or later (for TypeScript users)

Security Considerations

  • Token Expiration: Tokens are short-lived with a maximum lifetime of 12 hours. The actual expiry is min(specified duration, credentials expiry, 12 hours). Use the shortest practical duration for your use case.
  • Secure Storage: Do not log or store tokens in plain text. Treat them as sensitive credentials.
  • No Embedded Credentials: No long-term credentials are embedded in the token. The token contains a SigV4 presigned URL, not the signing keys themselves.
  • Credential Management: Use IAM roles or temporary credentials instead of long-term access keys where possible.
  • Network Security: Always transmit tokens over HTTPS.
  • Least Privilege: Scope IAM permissions to the minimum required for your use case.
  • Region Scoping: Tokens are scoped to a specific AWS region and cannot be used across regions.

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

Contributing

See CONTRIBUTING for more information.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Changelog

See CHANGELOG for release history.

版本与发布记录

@aws/token-generator-for-aws-external-anthropic 共发布 1 个版本,首次发布于 2026/05/08;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.0.0latest2026/05/086 个月前

关于 @aws/token-generator-for-aws-external-anthropic 的常见问题

@aws/token-generator-for-aws-external-anthropic 是什么?

A lightweight library for generating short-term bearer tokens for AWS External Anthropic API authentication

如何安装 @aws/token-generator-for-aws-external-anthropic?

在项目目录运行 npm install @aws/token-generator-for-aws-external-anthropic,或使用 pnpm add / yarn add / bun add。

@aws/token-generator-for-aws-external-anthropic 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws/token-generator-for-aws-external-anthropic 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aws/token-generator-for-aws-external-anthropic 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aws/token-generator-for-aws-external-anthropic 可以商用吗?

@aws/token-generator-for-aws-external-anthropic 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws/token-generator-for-aws-external-anthropic 的下载量有多少?

根据 npm 官方下载统计,@aws/token-generator-for-aws-external-anthropic 在 2026/10/08 – 2026/11/06 这 30 天内被下载 262,519 次,日均约 8,751 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws/token-generator-for-aws-external-anthropic 还在维护吗?

最新版本 1.0.0 发布于 2026/05/08(6 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。