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

@bradtjohnson1/asksage-token-generator

v1.2.0

Published

Secure utility for generating and managing Ask Sage API access tokens

Downloads

16

Readme

Ask Sage Token Generator (JavaScript/Node.js)

A Node.js utility to generate and manage access tokens for the Ask Sage API.

Features

  • Interactive credential setup
  • Secure token storage (OS keychain or file-based)
  • Automatic token validation
  • Token caching with 65-minute expiration (1 hour 5 minutes)
  • Easy integration with other JavaScript applications

Prerequisites

  • Node.js 14.0.0 or higher
  • npm (comes with Node.js)
  • Ask Sage account with API key

Quick Start

Installation & Setup

Option 1: Automated Setup (Windows)

setup.bat

This will:

  • Check Node.js installation
  • Install npm dependencies
  • Show instructions to run npm start

Option 2: Automated Setup (Linux/macOS/Node.js)

node setup.js

This will:

  • Check Node.js version
  • Install npm dependencies
  • Show instructions to run npm start

Option 3: Manual Setup

npm install

Generate a Token

npm start

The script will:

  1. Ask for your Ask Sage email
  2. Ask for your Ask Sage API key
  3. Save credentials to credentials.json
  4. Request token from Ask Sage API
  5. Validate the token
  6. Save token securely (OS keychain or file)
  7. Create asksage_config.json

Regenerate Token (credentials already saved)

npm start

The script will use your saved credentials automatically.


Getting Your API Key

  1. Go to https://asksage.ai
  2. Log in to your account
  3. Navigate to Account Settings
  4. Click "Manage your API keys"
  5. Create a new API key or copy an existing one

Using the Token

In API Requests

const axios = require('axios');

const headers = {
  'x-access-tokens': 'your_token_here',
  'Content-Type': 'application/json'
};

const response = await axios.post(
  'https://api.asksage.ai/server/get-models',
  {},
  { headers }
);

As a Module in Your Code

const { getStoredToken, getToken } = require('./asksage_token');

// Get stored token
const token = await getStoredToken('[email protected]');

// Or generate new token
const newToken = await getToken('[email protected]', 'your_api_key');

Using Environment Variable

The script sets the ASK_SAGE_TOKEN environment variable for the current session:

const token = process.env.ASK_SAGE_TOKEN;

Files Created

After running the token generator:

  • credentials.json - Your email and API key (gitignored)
  • asksage_config.json - Config with metadata (gitignored)
  • ~/asksage_token.txt - Token file (if keytar not available)

File Structure

javascript/
├── asksage_token.js           # Main token generator script
├── package.json               # npm package configuration
├── setup.bat                  # Windows setup script
├── setup.js                   # Cross-platform setup script
├── credentials.json.example   # Example credentials file
├── asksage_config.json.example # Example config file
├── .gitignore                 # Git ignore rules
└── README.md                  # This file

Security

Token Storage

The script uses multiple security layers:

  1. OS Keychain (Preferred): If keytar is installed, tokens are stored in your operating system's credential manager:

    • macOS: Keychain
    • Windows: Credential Vault
    • Linux: Secret Service API/libsecret
  2. File-based (Fallback): Tokens are stored in ~/asksage_token.txt with restricted permissions (600)

Installing Keytar (Optional but Recommended)

For enhanced security with OS keychain storage:

npm install keytar

Note: keytar requires native build tools on some systems. If installation fails, the script will fall back to file-based storage.

Best Practices

  • Never commit credentials.json to version control
  • Keep your API key secure
  • Tokens expire after 65 minutes (1 hour 5 minutes)
  • Use environment variables in production

Token Expiration

Ask Sage tokens expire after 65 minutes (1 hour 5 minutes). When your token expires:

  1. Run npm start again to generate a new token
  2. The script will automatically test the new token
  3. Your credentials remain saved for easy regeneration

Troubleshooting

"Node.js not found"

Install Node.js 14.0.0 or higher from https://nodejs.org

"Authentication failed"

  • Verify your email and API key in credentials.json
  • Ensure your API key is active and has the correct permissions

"keytar not available"

  • This is normal if keytar isn't installed
  • The script will use file-based storage instead
  • To install keytar (optional): npm install keytar

"Permission denied"

  • On Unix systems: Ensure you have write permissions to your home directory
  • On Windows: Run as administrator if needed

"Request timed out"

  • Check your internet connection
  • Verify the API endpoints are accessible

Support

For issues or questions:

  • Check the main README in the parent directory
  • Visit https://asksage.ai for API documentation
  • Contact Ask Sage support

License

MIT