
AI-Powered Content Generation: Best Practices and Use Cases
Discover how to leverage Contensa's AI content generation features to streamline your workflow and create high-quality content faster.
Learn how to set up Contensa CMS in minutes with this step-by-step guide covering installation, configuration, and fetching your first content.
Sarah Johnson
Technical Writer & Developer Advocate

Welcome to Contensa! This comprehensive guide will walk you through everything you need to know to get started with our powerful headless CMS platform. Whether you're building a marketing website, a mobile app, or a complex web application, Contensa provides the flexibility and performance you need.
Before diving into the setup process, let's explore what makes Contensa stand out:
Before you begin, ensure you have:
Install the SDK using your preferred package manager:
bash# Using npm npm install @mybe/sdk # Using yarn yarn add @mybe/sdk # Using pnpm pnpm add @mybe/sdk
Create a test file to verify the installation:
typescriptimport { MybeSDK } from '@mybe/sdk'; const sdk = new MybeSDK({ apiKey: 'your-api-key' }); console.log('SDK initialized successfully!');
Store your API credentials securely in environment variables:
MYBE_API_KEY=your-api-key-here
Security Note: Never commit API keys to version control. Always use environment variables or secure secrets management.
Initialize the SDK with your API key:
typescriptimport { MybeSDK } from '@mybe/sdk'; const sdk = new MybeSDK({ apiKey: process.env.MYBE_API_KEY });
The SDK automatically detects your environment:
NODE_ENV=development): Uses http://localhost:3001/api/v1https://api.mybe.app/api/v1Override the default base URL if needed:
typescriptconst sdk = new MybeSDK({ apiKey: process.env.MYBE_API_KEY, baseUrl: 'https://custom-api.example.com/api/v1' });
Now that your SDK is configured, let's fetch some content!
Retrieve a specific content entry by its ID:
typescript// Fetch content by ID const content = await sdk.getContent('content-id'); console.log(content.data); // Content data console.log(content.status); // 'draft' | 'published' | 'archived'
Get all entries for a specific content type:
typescript// Fetch published blog posts const result = await sdk.getContentByType('blog-post-type-id', { status: 'published', limit: 10 }); console.log(result.data); // Array of content entries console.log(result.pagination); // Pagination information
Customize your queries with these options:
status: Filter by content status ('draft', 'published', or 'archived')locale: Specify content locale for multilingual supportlimit: Number of results to returnlastKey: Pagination key for fetching next pagePerfect for dynamic routing and SEO-friendly URLs:
typescript// Fetch blog post by slug const post = await sdk.getContentByField( 'blog-type-id', 'slug', 'getting-started-with-contensa' ); // Fetch page by URL path const page = await sdk.getContentByField( 'page-type-id', 'href', '/about-us' ); // Returns null if not found (no error thrown) if (!post) { console.log('Content not found'); }
Get all content types in your project:
typescriptconst contentModels = await sdk.getContentModels('project-id'); contentModels.forEach(model => { console.log(model.name); console.log(model.fields); });
Retrieve details about a specific content type:
typescriptconst contentModel = await sdk.getContentModel('content-type-id'); console.log(contentModel.name); console.log(contentModel.fields); console.log(contentModel.metadata);
Implement robust error handling for a better user experience:
typescriptimport { NotFoundError, UnauthorizedError } from '@mybe/sdk'; try { const content = await sdk.getContent('content-id'); console.log(content); } catch (error) { if (error instanceof NotFoundError) { console.error('Content not found'); } else if (error instanceof UnauthorizedError) { console.error('Invalid API key - check your credentials'); } else { console.error('An unexpected error occurred:', error); } }
Here's a complete example for a Next.js blog page:
typescriptimport { MybeSDK } from '@mybe/sdk'; const sdk = new MybeSDK({ apiKey: process.env.MYBE_API_KEY }); // Next.js page component export default async function BlogPost({ params }) { try { // Fetch blog post by slug const post = await sdk.getContentByField( 'blog-type-id', 'slug', params.slug ); if (!post) { return <div>Post not found</div>; } return ( <article> <h1>{post.data.title}</h1> <div>{post.data.content}</div> <time>{post.data.publishedAt}</time> </article> ); } catch (error) { console.error('Error fetching post:', error); return <div>Error loading post</div>; } }
Congratulations! You've successfully set up Contensa and learned the basics. Here's what to explore next:
typescript// pages/[...slug].tsx export async function generateStaticParams() { const pages = await sdk.getContentByType('page-type-id', { status: 'published' }); return pages.data.map(page => ({ slug: page.data.href.split('/').filter(Boolean) })); }
typescriptasync function fetchAllPosts() { let allPosts = []; let lastKey = undefined; do { const result = await sdk.getContentByType('blog-type-id', { status: 'published', limit: 20, lastKey }); allPosts = [...allPosts, ...result.data]; lastKey = result.pagination.lastKey; } while (lastKey); return allPosts; }
If you receive unauthorized errors, verify:
When content returns null:
For connection issues:
If you encounter issues or have questions:
Happy building with Contensa! 🚀

Discover how to leverage Contensa's AI content generation features to streamline your workflow and create high-quality content faster.

A comprehensive guide to integrating Contensa's powerful GraphQL API into your applications with real-world examples and code snippets.

Learn how to manage multilingual content efficiently using Contensa's built-in localization features and reach a global audience.