Skip to main content

Crate tiktoken_wasm

Crate tiktoken_wasm 

Source
Expand description

WebAssembly bindings for the tiktoken BPE tokenizer.

Provides browser-compatible wrappers around the core tiktoken crate, enabling high-performance token encoding, decoding, counting, and cost estimation directly in JavaScript/TypeScript applications.

All encoding instances are cached globally via OnceLock, so repeated calls to getEncoding() with the same name return the same underlying data.

Structs§

Encoding
WASM wrapper around a tiktoken encoding instance.
ModelInfo
Model pricing and metadata.

Functions§

all_models
List all supported models with pricing info.
encoding_for_model
Get an encoding for a model name (e.g. "gpt-4o", "o3-mini", "llama-4", "deepseek-r1").
estimate_cost
Estimate cost in USD for a given model, input token count, and output token count.
get_encoding
Get an encoding by name.
get_model_info
Get model pricing and metadata.
list_encodings
List all available encoding names.
model_to_encoding
Map a model name to its encoding name without loading the encoding.
models_by_provider
List models filtered by provider name.