API Reference
Complete reference for the TridentClient API.
createTridentClient
Factory function to create a new Trident client instance.
function createTridentClient(config: TridentClientConfig): TridentClientTridentClientConfig
| Property | Type | Default | Description |
|---|---|---|---|
| apiKey | string | Required | Your Trident API key |
| baseUrl | string? | https://app.tridentseo.ai/api/v1/public | API base URL |
| timeout | number? | 30000 | Request timeout in ms |
| fetch | typeof fetch? | globalThis.fetch | Custom fetch function |
| retry | RetryOptions? | - | Retry transient 429/5xx errors |
| validateResponses | boolean? | false | Validate API responses at runtime |
client.getArticles()
Fetch a paginated list of published articles.
async getArticles(options?: GetArticlesOptions): Promise<{
data: Article[];
pagination: Pagination;
}>Options
| Property | Type | Description |
|---|---|---|
| product | string? | Filter by product slug |
| territory | string? | Filter by territory code |
| limit | number? | Number of articles (default: 20, max: 100) |
| offset | number? | Pagination offset |
client.getAllArticles()
Fetch all published articles across pages.
async getAllArticles(options?: GetAllArticlesOptions): Promise<Article[]>Options
| Property | Type | Description |
|---|---|---|
| product | string? | Filter by product slug |
| territory | string? | Filter by territory code |
| limit | number? | Page size (default: 100, max: 100) |
| maxPages | number? | Limit total pages fetched |
client.getArticle()
Fetch a single article by its slug.
async getArticle(
slug: string,
options?: GetArticleOptions
): Promise<Article>Throws
TridentNotFoundErrorif article doesn't existTridentAuthErrorif API key is invalid
client.getSitemap()
Fetch all sitemap entries for generating sitemap.xml.
async getSitemap(): Promise<SitemapEntry[]>SitemapEntry
interface SitemapEntry {
slug: string;
productSlug: string;
languageCode: string;
territoryCode: string;
publishedAt: string | null;
updatedAt: string;
}client.getLastRequestId()
Read the last request ID returned by the API (if available).
getLastRequestId(): string | nullError Classes
All errors extend TridentError and include error codes and HTTP status codes.
| Error Class | Status | Description |
|---|---|---|
| TridentAuthError | 401 | Invalid or missing API key |
| TridentForbiddenError | 403 | Insufficient permissions |
| TridentNotFoundError | 404 | Resource not found |
| TridentRateLimitError | 429 | Rate limit exceeded |
| TridentValidationError | 400 | Invalid request parameters |
| TridentAPIError | 5xx | Server error |
| TridentNetworkError | - | Network/connection error |
| TridentResponseError | - | Invalid API response shape |
| TridentTimeoutError | - | Request timeout |
Error Handling Example
import {
TridentNotFoundError,
TridentRateLimitError,
} from "@trident/client";
try {
const article = await client.getArticle(slug);
} catch (error) {
if (error instanceof TridentNotFoundError) {
// Article doesn't exist
notFound();
}
if (error instanceof TridentRateLimitError) {
// Wait and retry
console.log(`Retry after: ${error.retryAfter}s`);
}
throw error;
}