Dictionary SDK Reference
Official JavaScript/TypeScript SDK for the Dictionary API. Build language tools, educational apps, and AI-powered text processing with our comprehensive word intelligence platform.
Installation
Install the Dictionary SDK using your preferred package manager:
npm install @dictionary/sdk
# or
yarn add @dictionary/sdk
# or
pnpm add @dictionary/sdk
Initialization
Import and configure the SDK with your API credentials. You can obtain your API key from the Dictionary Developer Dashboard.
import { Dictionary } from '@dictionary/sdk';
const client = new Dictionary({
apiKey: process.env.DICTIONARY_API_KEY,
region: 'us-east-1', // Optional
timeout: 5000 // Optional (ms)
});
search() async
Search for word definitions, etymologies, and usage examples.
word: string,
options?: SearchOptions
) => Promise<SearchResult>
Parameters
| Parameter | Type | Description |
|---|---|---|
word required | string | The word or phrase to search for |
language optional | string | ISO 639-1 language code (default: 'en') |
partsOfSpeech optional | string[] | Filter by POS: ['noun', 'verb', 'adjective'] |
Example
const result = await client.search('ephemeral', {
partsOfSpeech: ['adjective']
});
console.log(result.definitions[0].meaning);
// "Lasting for a very short time; transitory."
getSynonyms() async
Retrieve context-aware synonyms and antonyms for a given word.
word: string,
options?: { includeAntonyms?: boolean }
) => Promise<SynonymResult>
const syns = await client.getSynonyms('joyful', { includeAntonyms: true });
// Returns: { synonyms: ['happy', 'elated', 'cheerful'], antonyms: ['sad', 'gloomy'] }
translate() async
Context-aware translation across 100+ languages with dialect support.
text: string,
targetLang: string,
options?: { sourceLang?: string; context?: string }
) => Promise<TranslationResult>
Configuration
The SDK accepts a configuration object during initialization. All options are optional unless marked required.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | - | Your secret API key |
region | string | 'us-east-1' | API endpoint region |
timeout | number | 5000 | Request timeout in milliseconds |
retries | number | 3 | Automatic retry count on failure |
cache | boolean | true | Enable local response caching |
Error Handling
The SDK throws standardized error objects for all API failures. Catch and handle them gracefully in your application.
import { DictionaryError } from '@dictionary/sdk';
try {
const result = await client.search('word');
} catch (error) {
if (error instanceof DictionaryError) {
console.error(`[${error.code}] ${error.message}`);
// Handle: INVALID_API_KEY, RATE_LIMITED, NOT_FOUND, etc.
}
}
Rate Limits
API requests are throttled based on your subscription tier:
- Free Tier: 100 requests/minute
- Pro Tier: 1,000 requests/minute
- Enterprise: Custom limits with dedicated throughput
When rate limited, the SDK automatically queues and retries requests with exponential backoff up to the configured retry limit.