Skip to main content

addToken

codebolt.tokenizer.addToken(key: string): Promise<AddTokenResponse>
Adds a token to the system and returns tokenized array.

Parameters

NameTypeDescription
keystringThe key/string to be tokenized.

Returns:

 Promise<AddTokenResponse>
A promise that resolves with the tokenization response.

Response Structure

{
type: 'addTokenResponse',
message: 'success',
tokens: number[] // Array of token IDs
}

Example

import codebolt from '@codebolt/codeboltjs';

async function addTokenExample() {
try {
const response = await codebolt.tokenizer.addToken("api_key_1");
console.log("Token added:", response);
// Output: {
// type: 'addTokenResponse',
// message: 'success',
// tokens: [15042, 62, 2539, 62, 16]
// }
} catch (error) {
console.error("Failed to add token:", error);
}
}

addTokenExample();