API Reference

Complete reference for the TridentClient API.

createTridentClient

Factory function to create a new Trident client instance.

function createTridentClient(config: TridentClientConfig): TridentClient

TridentClientConfig

PropertyTypeDefaultDescription
apiKeystringRequiredYour Trident API key
baseUrlstring?https://app.tridentseo.ai/api/v1/publicAPI base URL
timeoutnumber?30000Request timeout in ms
fetchtypeof fetch?globalThis.fetchCustom fetch function
retryRetryOptions?-Retry transient 429/5xx errors
validateResponsesboolean?falseValidate API responses at runtime

client.getArticles()

Fetch a paginated list of published articles.

async getArticles(options?: GetArticlesOptions): Promise<{
  data: Article[];
  pagination: Pagination;
}>

Options

PropertyTypeDescription
productstring?Filter by product slug
territorystring?Filter by territory code
limitnumber?Number of articles (default: 20, max: 100)
offsetnumber?Pagination offset

client.getAllArticles()

Fetch all published articles across pages.

async getAllArticles(options?: GetAllArticlesOptions): Promise<Article[]>

Options

PropertyTypeDescription
productstring?Filter by product slug
territorystring?Filter by territory code
limitnumber?Page size (default: 100, max: 100)
maxPagesnumber?Limit total pages fetched

client.getArticle()

Fetch a single article by its slug.

async getArticle(
  slug: string,
  options?: GetArticleOptions
): Promise<Article>

Throws

  • TridentNotFoundError if article doesn't exist
  • TridentAuthError if 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 | null

Error Classes

All errors extend TridentError and include error codes and HTTP status codes.

Error ClassStatusDescription
TridentAuthError401Invalid or missing API key
TridentForbiddenError403Insufficient permissions
TridentNotFoundError404Resource not found
TridentRateLimitError429Rate limit exceeded
TridentValidationError400Invalid request parameters
TridentAPIError5xxServer 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;
}