Next-Blog-AI
Home/Documentation/API Reference/Overview

API Reference

All functions documented below are specific to Next.js projects and available via createNextBlogAIForNextJs.

createNextBlogAIForNextJs

Initializes the Next-Blog-AI client for Next.js and returns API methods with Next.js-optimized cache support.

Function Signature

createNextBlogAIForNextJs(apiKey: string, defaultCacheOptions?: NextCacheOptions): { client, getBlogPosts, getBlogPost, getBlogPostSEO, getBlogListSEO, getAllBlogSlugs }

Input Parameters

NameTypeOptionalDefault ValueDescription
apiKeystringNoYour Next-Blog-AI API key.
defaultCacheOptionsNextCacheOptionsYesDefault Next.js caching options (ISR, dynamic, etc.).
revalidatenumberYes0ISR seconds
dynamicbooleanYesfalseForce dynamic rendering

Return Parameters

NameTypeOptionalDefault ValueDescription
clientobjectNoThe underlying API client.
getBlogPostsfunctionNoFetch blog post list.
getBlogPostfunctionNoFetch a single blog post.
getBlogPostSEOfunctionNoFetch SEO metadata for a post.
getBlogListSEOfunctionNoFetch SEO metadata for the blog list.
getAllBlogSlugsfunctionNoFetch all blog slugs.

Types & Interfaces

type NextCacheOptions = {
  revalidate?: number; // ISR seconds
  dynamic?: boolean;  // Force dynamic rendering
}

Example Usage

import { createNextBlogAIForNextJs } from 'next-blog-ai';

const { getBlogPosts } = createNextBlogAIForNextJs(process.env.NEXT_BLOG_AI_API_KEY!);
const { data, error } = await getBlogPosts({ next: { revalidate: 3600 } }); // ISR: 1 hour

getBlogPosts

Fetch a paginated list of blog posts with Next.js cache control.

Function Signature

getBlogPosts(options?: NextBlogListOptions): Promise<ApiResponse<BlogListResponse>>

Input Parameters

NameTypeOptionalDefault ValueDescription
optionsNextBlogListOptionsYesOptions for pagination, format, and Next.js cache.
pagenumberYesPage number
perPagenumberYesPosts per page
format'html' | 'json'Yes'html'Response format
display'grid' | 'list'YesDisplay type
next{ revalidate?: number; dynamic?: boolean }Yes{ revalidate: 0; dynamic: false }Next.js cache options

Return Parameters

NameTypeOptionalDefault ValueDescription
dataBlogListResponseNoBlog post list data.
errorstringYesError message, if any.

Types & Interfaces

interface NextBlogListOptions {
  page?: number;
  perPage?: number;
  format?: 'html' | 'json';
  display?: 'grid' | 'list';
  next?: { revalidate?: number; dynamic?: boolean };
}

// BlogListResponse is a union type based on format
type BlogListResponse = BlogListHtmlResponse | BlogListJsonResponse;

// HTML format response
interface BlogListHtmlResponse {
  format: 'html';
  content: string; // HTML content with inline styles
  seo: SEOMetadata;
  pagination: Pagination;
}

// JSON format response
interface BlogListJsonResponse {
  format: 'json';
  posts: BlogPostSummary[];
  seo: SEOMetadata;
  pagination: Pagination;
}

// Blog post summary for list views
interface BlogPostSummary {
  id: string;
  title: string;
  slug: string;
  excerpt: string;
  featuredImageUrl?: string;
  publishedAt: string;
  readingTime: number;
  commentCount: number;
  language: string;
}

// Pagination information
interface Pagination {
  totalPosts: number;
  totalPages: number;
  currentPage: number;
  perPage: number;
}

Example Usage

const { data, error } = await nextBlogAI.getBlogPosts({
  page: 1,
  perPage: 10,
  format: 'html',
  next: { revalidate: 3600 },
});

getBlogPost

Fetch a single blog post with Next.js cache control.

Function Signature

getBlogPost(slug: string, options?: NextBlogPostOptions): Promise<ApiResponse<BlogPostResponse>>

Input Parameters

NameTypeOptionalDefault ValueDescription
slugstringNoThe slug of the blog post to fetch.
optionsNextBlogPostOptionsYesOptions for format and Next.js cache.
format'html' | 'json'Yes'html'Response format
next{ revalidate?: number; dynamic?: boolean }Yes{ revalidate: 0; dynamic: false }Next.js cache options

Return Parameters

NameTypeOptionalDefault ValueDescription
dataBlogPostResponseNoBlog post data.
errorstringYesError message, if any.

Types & Interfaces

interface NextBlogPostOptions {
  format?: 'html' | 'json';
  next?: { revalidate?: number; dynamic?: boolean };
}

// BlogPostResponse is a union type based on format
type BlogPostResponse = BlogPostHtmlResponse | BlogPostJsonResponse;

// HTML format response
interface BlogPostHtmlResponse {
  format: 'html';
  content: string; // HTML content with inline styles
  commentForm: string; // HTML for comment form
  comments: string; // HTML for comments
  seo: SEOMetadata;
}

// JSON format response
interface BlogPostJsonResponse {
  format: 'json';
  post: BlogPost;
  comments: Comment[];
  seo: SEOMetadata;
}

// Full blog post
interface BlogPost {
  id: string;
  title: string;
  slug: string;
  content: string;
  excerpt: string;
  featuredImageUrl?: string;
  publishedAt: string;
  readingTime: number;
  language: string;
}

// Comment on a blog post
interface Comment {
  id: string;
  authorName: string;
  content: string;
  createdAt: string;
}

Example Usage

const { data, error } = await nextBlogAI.getBlogPost('my-post-slug', {
  format: 'html',
  next: { revalidate: 3600 },
});

getBlogPostSEO

Fetch SEO metadata for a blog post with Next.js cache control.

Function Signature

getBlogPostSEO(slug: string, options?: NextSEOOptions): Promise<ApiResponse<SEOResponse>>

Input Parameters

NameTypeOptionalDefault ValueDescription
slugstringNoThe slug of the blog post to fetch SEO metadata for.
optionsNextSEOOptionsYesOptions for Next.js cache.

Return Parameters

NameTypeOptionalDefault ValueDescription
dataSEOResponseNoSEO metadata for the blog post.
errorstringYesError message, if any.

Types & Interfaces

interface NextSEOOptions {
  next?: { revalidate?: number; dynamic?: boolean };
}

interface SEOResponse {
  seo: SEOMetadata;
}

interface SEOMetadata {
  title: string;
  description: string;
  keywords: string[];
  structuredData: string | object;
  featuredImage?: {
    url: string;
    alt: string;
  };
}

Example Usage

const { data } = await nextBlogAI.getBlogPostSEO('my-post-slug', {
  next: { revalidate: 3600 },
});

getBlogListSEO

Fetch SEO metadata for the blog list with Next.js cache control.

Function Signature

getBlogListSEO(options?: NextBlogListSEOOptions): Promise<ApiResponse<BlogListSEOResponse>>

Input Parameters

NameTypeOptionalDefault ValueDescription
optionsNextBlogListSEOOptionsYesOptions for Next.js cache.
next{ revalidate?: number; dynamic?: boolean }Yes{ revalidate: 0; dynamic: false }Next.js cache options

Return Parameters

NameTypeOptionalDefault ValueDescription
dataBlogListSEOResponseNoSEO metadata for the blog list.
errorstringYesError message, if any.

Types & Interfaces

interface NextBlogListSEOOptions {
  next?: { revalidate?: number; dynamic?: boolean };
}

interface BlogListSEOResponse {
  seo: SEOMetadata;
}

Example Usage

const { data } = await nextBlogAI.getBlogListSEO({
  next: { revalidate: 3600 },
});

getAllBlogSlugs

Fetch all blog slugs with Next.js cache control.

Function Signature

getAllBlogSlugs(options?: NextBlogSlugsOptions): Promise<ApiResponse<BlogSlugsResponse>>

Input Parameters

NameTypeOptionalDefault ValueDescription
optionsNextBlogSlugsOptionsYesOptions for Next.js cache.
next{ revalidate?: number; dynamic?: boolean }Yes{ revalidate: 0; dynamic: false }Next.js cache options

Return Parameters

NameTypeOptionalDefault ValueDescription
dataBlogSlugsResponseNoArray of blog slugs.
errorstringYesError message, if any.

Types & Interfaces

interface NextBlogSlugsOptions {
  next?: { revalidate?: number; dynamic?: boolean };
}

interface BlogSlugsResponse {
  slugs: string[];
}

Example Usage

const { data } = await nextBlogAI.getAllBlogSlugs({
  next: { revalidate: 600 },
});