Add AI Features to Your App: OpenAI, Anthropic, Gemini | SheCodes
Advanced 6 min read

AI Integration Guide

Add AI-powered features to your app: chatbots, content generation, summarization, and more. No machine learning degree required.

In this chapter

  • What it takes to add AI features like chat or summarization
  • How API keys work and why they must stay on the backend
  • Which AI model to pick for different jobs (and what each costs)
  • Copy-paste prompts to plug AI into your existing project

What You Can Add

Chatbot A conversational interface where users ask questions and get answers. Great for customer support, documentation helpers, and interactive assistants.
Content Generation Auto-generate blog posts, product descriptions, email drafts, or social media captions. Users provide a topic or outline, AI writes the content.
Summarization Condense long articles, meeting notes, or documents into key points. Users paste text or upload a document and get a brief summary back.
Image Generation Create images from text descriptions using OpenAI's GPT Image, Google's Nano Banana, or open models like Flux and Stable Diffusion. Users type 'a cat in space' and get a generated image back.
Smart Search Use AI embeddings to search by meaning, not just keywords. Search 'comfortable shoes for walking' and find results even if they don't contain those exact words.
Classification Automatically categorize content: sort support tickets by urgency, tag blog posts by topic, or detect sentiment in reviews (positive/negative/neutral).

Pick Your AI Provider

The big three are OpenAI, Anthropic Claude, and Google Gemini. They all do roughly the same things, and all three now read up to about 1 million tokens at once. The differences are price, free tier, tooling, and vibe. Start here before you commit to one.

Provider Free tier? Typical cost Pick it for
OpenAI (GPT-6 models) Pay-as-you-go $ – $$ Broadest tooling, image generation (GPT Image), the safe default
Anthropic (Claude) Small test credit $ – $$ Following instructions, writing, long documents, code
Google (Gemini) ✓ Real free tier $ – $$ Side projects, images + video in, free to start
Open-source (Replicate, HF, Groq) Varies Varies Niche models, image/audio, ultra-fast inference (Groq)
Anthropic API (Claude) The company behind Claude. Known for being careful, nuanced, and the best at following complex instructions. Excellent for long documents, writing, and code. Pros
  • Best at following instructions precisely
  • Handles 1M-token contexts (several books at once)
  • Strong reasoning, writing, and coding
Cons
  • No image generation (input only)
  • No free tier, just a small test credit
Best for: Writing, analysis, long documents, code
Google Gemini API Has free tier Google's AI family. Gemini Flash and Flash-Lite are cheap and fast, and the Gemini 4 models are the heavyweights. Native support for images, video, and audio, with a 1M-token context window. Pros
  • Real free tier: low rate limits but zero cost
  • Multimodal: takes images, video, audio as input
  • Huge context: 1M tokens
  • Built-in image generation (Nano Banana)
Cons
  • Free-tier inputs may be used to train Google's models
  • Smaller ecosystem than OpenAI
Best for: Side projects, long docs, multimodal inputs
Replicate A platform that lets you run open-source AI models via API. Access Stable Diffusion, Llama, Whisper, and thousands of others without managing servers. Pros
  • Thousands of open-source models
  • Pay per second, no minimum
  • Best for image, video, and audio models
Cons
  • Cold starts can be slow (5–30s)
  • Open-source model quality varies
Best for: Image generation and specialized models
Groq Not a model maker: an ultra-fast inference service that runs open models (Llama and OpenAI's gpt-oss) on custom hardware. Known for responses that appear almost instantly. Pros
  • Blazingly fast: 10x+ faster than typical APIs
  • OpenAI-compatible API format
Cons
  • Only runs open-source models
  • Fewer model options than Replicate
Best for: Speed-sensitive chat apps and demos
Hugging Face The open-source AI hub. Browse and download models for free, or run 200+ of them through one API (Inference Providers, pay as you go). Huge model library covering text, image, audio, and more. Pros
  • Massive free model library
  • Community-driven, new models daily
  • One API for models from many providers
Cons
  • No free inference credits: you buy credits (PRO includes $2/month)
  • Requires more knowledge to pick the right model
Best for: Experimenting and finding niche models

Key Concepts

API Keys A secret password that lets your app talk to an AI service. You get one from the provider's dashboard. Never put it in your frontend code. Store it in .env.local and only use it on the server side.
Tokens How AI models measure text. One token is roughly 4 characters or 3/4 of a word. You pay per token (input + output). A 500-word response uses about 650 tokens. Set max token limits to control costs.
Streaming Instead of waiting for the entire response, display words as they come in, like watching someone type. Makes the app feel faster and more responsive. Essential for chat interfaces.
System Prompts Instructions you give the AI model before the user's message. 'You are a helpful customer support agent for a shoe store. Be friendly and concise.' This controls the AI's personality and behavior.

UI Patterns for AI Features

Chat Interface
  • Message bubbles (user on right, AI on left)
  • Text input with send button at bottom
  • Auto-scroll to newest message
  • Typing indicator while AI responds
Streaming Responses
  • Words appear one by one, like typing
  • Cursor blinks at the end of the text
  • Stop button to cancel generation
  • Smooth scrolling as text grows
Loading States
  • Animated dots or spinner while waiting
  • Skeleton text placeholders
  • 'Thinking...' or 'Generating...' labels
  • Estimated time for long operations

Tools & SDKs

Vercel AI SDK The easiest way to add AI to a Next.js app. Handles streaming, chat state, and provider switching with just a few lines of code. Works with OpenAI, Anthropic, and more. Streaming built-in Made by Vercel Multi-provider
LangChain A framework for building complex AI workflows. Chain multiple AI calls together, add memory to conversations, connect AI to your database, and build agents that can use tools. Complex workflows Tool usage Memory & RAG

AI Prompts for Adding AI Features

Copy-paste these prompts to quickly add AI features to your project.

“Add an AI chat widget using the OpenAI API with streaming responses. Show messages in a chat bubble layout with the user on the right and AI on the left. Include a text input and send button.”

“Set up the Gemini API in my Next.js app using the free tier. Create an /api/chat route that uses the latest Gemini Flash model with streaming, and show me the env variable I need and where to get the API key.”

“Swap the chat widget in my project from OpenAI to Gemini using the Vercel AI SDK. Keep everything else the same and point me to which env variables I need to change.”

“Add a 'Generate Description' button next to my product form. When clicked, use the AI to generate a product description based on the product name and category fields. Show a loading spinner.”

“Add a text summarization feature. Users paste an article into a textarea and click 'Summarize'. Use the Anthropic API to return a 3-bullet summary. Stream the response.”

“Set up the Vercel AI SDK with OpenAI in my Next.js app. Create an API route at /api/chat and a chat page with streaming messages, a stop button, and conversation history.”

“Add an AI-powered search to my documentation site. Use OpenAI embeddings to find the most relevant docs based on the user's question, then generate a natural language answer with citations.”

Frequently Asked Questions

How much does it cost to add AI features to my app?

AI providers charge per token (roughly per word). A typical chat message costs $0.001-0.01. For a small app, expect $5-20/month. Gemini has a real free tier for low-volume use. Anthropic gives new accounts a small test credit, and OpenAI is pay-as-you-go from the start.

Which AI model should I use?

For side projects, start with Gemini Flash: it has a free tier. For serious products, OpenAI's GPT-6 models (broadest ecosystem) or Claude (best at following instructions). For cheap bulk work like classification or summarization, use each provider's smallest model: GPT-6 Luna, Claude Haiku, or Gemini Flash-Lite. Model names change every few months, so ask your AI tool to check the provider's models page for the current one.

Is Gemini really free?

Yes, for low volume. You get a daily token quota on Gemini Flash with per-minute rate limits. Two catches: free-tier inputs may be used to train Google's models, and you'll hit the rate limits fast if your app gets popular. Paid mode opts you out of training.

Can I switch providers later?

Yes, use the Vercel AI SDK. It wraps OpenAI, Anthropic, Gemini, and more behind a unified interface. Start with one provider, then swap models in a single line of code if you need better quality, lower cost, or a free tier.

How do I keep my API key safe?

Never put your API key in frontend code. Anyone can see it in the browser. Always call AI APIs from your backend (API routes in Next.js). Store the key in environment variables and never commit it to Git. Your AI tool knows how to set this up securely.