API Reference/

SDKs

TypeScript SDK

The official TypeScript SDK for the Anagrama API. Works in Node.js, Deno, Bun, and edge runtimes. Fully typed with zero dependencies.

Installation

npm
npm install @anagramagames/sdk
yarn
yarn add @anagramagames/sdk
pnpm
pnpm add @anagramagames/sdk

Configuration

Create a client with your API key. The SDK automatically reads ANAGRAMA_API_KEY from the environment, so you can omit it if the env var is set.

.env
ANAGRAMA_API_KEY=ak_your_key_here
TypeScript
import Anagrama from "@anagramagames/sdk";

// Explicit key
const client = new Anagrama({
  apiKey: "ak_your_key_here",
});

// Or reads ANAGRAMA_API_KEY from env automatically
const client = new Anagrama();

First request

TypeScript
import Anagrama from "@anagramagames/sdk";

const client = new Anagrama();

// Fetch 3 random words between 5-8 letters
const response = await client.words.getRandom({
  count: 3,
  minLength: 5,
  maxLength: 8,
});
console.log(response.words);
// => ["tiger", "flame", "grove"]
console.log(response.count);
// => 3

Parameters: count (1–10, default 1), minLength (3–15, default 3), maxLength (3–15, default 15). All optional.

Common patterns

Daily word

TypeScript
const { word, date } = await client.words.getDaily();
console.log(`Today's word (${date}): ${word}`);
// => "Today's word (2026-02-15): flame"

Validate a word

TypeScript
const result = await client.words.validate({ word: "flame" });
console.log(result.valid);
// => true

Generate a puzzle

TypeScript
const puzzle = await client.puzzles.generate({ difficulty: "medium" });
console.log(puzzle.target, puzzle.scramble);

Dictionary lookup

TypeScript
const entry = await client.dictionary.lookup("flame");
console.log(entry.word, entry.results.length);

Fetch a wordset

TypeScript
const wordset = await client.wordsets.retrieve("ws_Ab3xK9mQ", {
  random: "true",
  limit: 5,
  scramble: "true",
});
console.log(wordset.name, wordset.wordCount);
// => "Animals" 5

Error handling

API errors throw typed error classes. Use instanceof to handle specific status codes:

TypeScript
import Anagrama, {
  BadRequestError,
  AuthenticationError,
  RateLimitError,
} from "@anagramagames/sdk";

const client = new Anagrama();

try {
  await client.words.getRandom({ count: 3 });
} catch (err) {
  if (err instanceof RateLimitError) {
    console.error("Rate limited:", err.status);  // 429
    console.error(err.message);
  } else if (err instanceof AuthenticationError) {
    console.error("Bad API key:", err.status);    // 401
  } else if (err instanceof BadRequestError) {
    console.error("Invalid params:", err.message); // 400
  }
}

Type safety

All request params and responses are fully typed. Access types via the Anagrama namespace:

TypeScript
import Anagrama from "@anagramagames/sdk";

const client = new Anagrama();

const params: Anagrama.WordGetRandomParams = {
  count: 3,
  minLength: 5,
  maxLength: 8,
};

const response: Anagrama.WordGetRandomResponse =
  await client.words.getRandom(params);
Was this page helpful?
Anagrama API Docs | Developer Reference