npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

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

v1.0.0

Published

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

Downloads

126

Readme

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.