
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
js-tiktoken
Advanced tools
tiktoken is a BPE tokeniser for use with OpenAI's models. This is a pure JS port of the original tiktoken library.
Install the library from NPM:
npm install js-tiktoken
You can only load the ranks you need, which will significantly reduce the bundle size:
import { Tiktoken } from "js-tiktoken/lite";
import o200k_base from "js-tiktoken/ranks/o200k_base";
const enc = new Tiktoken(o200k_base);
assert(enc.decode(enc.encode("hello world")) === "hello world");
Alternatively, encodings can be loaded dynamically from our CDN hosted on Cloudflare Pages.
import { Tiktoken } from "js-tiktoken/lite";
const res = await fetch(`https://tiktoken.pages.dev/js/o200k_base.json`);
const o200k_base = await res.json();
const enc = new Tiktoken(o200k_base);
assert(enc.decode(enc.encode("hello world")) === "hello world");
If you need all the OpenAI tokenizers, you can import the entire library:
[!CAUTION] This will include all the OpenAI tokenizers, which may significantly increase the bundle size. See
import assert from "node:assert";
import { getEncoding, encodingForModel } from "js-tiktoken";
const enc = getEncoding("gpt2");
assert(enc.decode(enc.encode("hello world")) === "hello world");
FAQs
JavaScript port of tiktoken
The npm package js-tiktoken receives a total of 1,220,171 weekly downloads. As such, js-tiktoken popularity was classified as popular.
We found that js-tiktoken demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.