Indie hackers often need fast, cheap AI that can write copy, generate code snippets, or answer user questions. ChatGPT fits that need perfectly. This guide explains what ChatGPT is, how to set it up, core workflows you can copy‑paste, advanced patterns for scaling, and the most common mistakes that waste time and money.
ChatGPT is a large language model (LLM) that predicts the next word in a sentence. It works through an API that accepts a list of messages – each message has a role (system, user, assistant) and content. The model returns a new assistant message.
Two versions matter for indie projects:
The cost model is pay‑as‑you‑go. In June 2024 the price was $0.002 per 1 k tokens for GPT‑3.5‑Turbo and $0.03 per 1 k for GPT‑4‑Turbo. A typical 150‑word response costs less than $0.01.
Go to platform.openai.com, verify your email and add a payment method. The free tier gives you $5 of credit and 25 messages per 3 hours.
In the dashboard, click **API keys → Create new secret key**. Copy it; you will need it in your code. Treat it like a password.
For Node.js:
npm install openai
For Python:
pip install openai
import { Configuration, OpenAIApi } from "openai";
const config = new Configuration({ apiKey: process.env.OPENAI_API_KEY });
const client = new OpenAIApi(config);
async function run() {
const response = await client.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role:"user", content:"Write a 50‑word tagline for a SaaS startup."}]
});
console.log(response.data.choices[0].message.content);
}
run();
Store the key in a .env file and load it with dotenv (Node) or python-dotenv (Python). Never commit the key to Git.
Prompt template:
System: You are a copywriter for indie SaaS products.
User: Write three headlines for a tool that helps freelancers track time.
Result: three concise headlines you can test in ads.
Prompt example for a Next.js API route:
System: You are a senior full‑stack developer.
User: Create a Next.js API route that receives an email and returns a 200 JSON response.
Copy the output, save as pages/api/subscribe.js, and run npm run dev. Adjust as needed.
Use OpenAI’s moderation endpoint to filter user input, then forward the cleaned text to ChatGPT. Return the assistant message to the front‑end.
Pass a long article (up to 128 k tokens with GPT‑4‑Turbo) and ask for a 3‑sentence summary. Useful for newsletters or weekly digests.
Define a JSON schema that describes a function you want the model to invoke. Example: a searchProducts function that returns product IDs.
{
"name": "searchProducts",
"description": "Find products that match a query",
"parameters": {
"type": "object",
"properties": {
"query": {"type":"string","description":"Search term"}
},
"required":["query"]
}
}
When the model returns a function call, execute it on your server and feed the result back as a new message.
Store your knowledge base in Pinecone or Supabase vector store. For each user query, embed the query, fetch top‑k documents, and prepend them as system messages. This gives factual answers without hallucination.
Set stream:true in the API call. In Node, pipe the event stream to the client with Server‑Sent Events. This makes the UI feel instant.
OpenAI returns HTTP 429 when you exceed limits. Implement exponential back‑off:
await new Promise(r=>setTimeout(r, Math.pow(2,attempt)*1000));
Log usage.prompt_tokens and usage.completion_tokens from each response. Multiply by the per‑token price to keep daily spend under control.
GPT‑3.5‑Turbo caps at 4 k tokens total (prompt + response). If you concatenate many messages, you’ll hit the limit and get cut‑off answers. Trim old messages or switch to GPT‑4‑Turbo for larger context.
Adding too many instructions confuses the model and wastes tokens. Keep system messages under 50 words. Test variations with A/B experiments.
Network failures, 429, or 500 responses cause crashes. Wrap API calls in try/catch and return a friendly fallback message like “Sorry, I’m having trouble right now.”
User input can contain hate speech or personal data. Run every input through /v1/moderations. Block or sanitize unsafe content before sending it to the model.
ChatGPT has no memory of your brand unless you tell it. Include a short brand description in the system prompt each session.
| Feature | Free Tier | ChatGPT Pro ($20/mo) | Enterprise (custom) |
|---|---|---|---|
| Model access | GPT‑3.5‑Turbo only | GPT‑3.5‑Turbo + GPT‑4‑Turbo (limited) | All models + dedicated capacity |
| Message limit | 25 msgs/3 h | Unlimited (subject to rate limits) | Higher rate limits |
| Token price | $0.002 /1k (3.5) | $0.002 /1k (3.5) $0.03 /1k (4) | Negotiated discounts |
| Priority support | Community only | Email support | Dedicated account manager |
| Fine‑tuning | No | No | Custom fine‑tune (beta) |
You can start with the free tier. It gives 25 messages every 3 hours and access to GPT‑3.5. For higher limits or GPT‑4, the $20/month Pro plan is usually enough for most indie apps.
Install the official OpenAI npm package, set your API key, and call openai.chat.completions.create() with a messages array. A minimal example is provided in the “Setup” section.
As of 2024, OpenAI offers “custom instructions” and “function calling” but not full fine‑tuning for GPT‑4. You can embed your data in prompts or use embeddings with a vector store.
Relying on a single prompt, ignoring token limits, and not handling rate‑limit errors. The “Common Mistakes” section explains each in detail.
ChatGPT does not store prompts, but you must filter outputs for profanity or PII. Use OpenAI’s moderation endpoint before showing results to users.
ChatGPT is a versatile tool that can accelerate product development, marketing, and support for indie hackers. Start small, monitor costs, and iterate on prompts. The right workflow saves time and keeps your budget under control.