Build with AI APIs — OpenAI, Anthropic, Google
Call AI APIs in your apps — free credits, India-friendly options
Building your own AI-powered application is the fastest way to understand how these tools work and to create something genuinely useful. With free API credits from major providers and simple Python/Node.js SDKs, you can build a working chatbot in under an hour. This guide takes you from API key to deployed app.
What You'll Learn
- Choosing the right AI API for your project
- Getting API keys and understanding free credits
- Building a simple chatbot in Python and Node.js
- Understanding token costs and staying within budget
- India-friendly payment options for API access
Choosing an AI API
There are three major API providers worth considering:
OpenAI API (GPT-5.3 Codex and GPT-5 family)
- Best for: creative content, general-purpose chatbots, structured output
- Pricing: $0.15/million input tokens (GPT-5.3 Codex), $10-30/million (GPT-5 full)
- Free credits: $5 for new accounts — enough to build and test several small projects
- Payment: Credit card required. Indian Visa/Mastercard works. Rupay may have issues.
Anthropic API (Claude 4.6 family)
- Best for: coding assistants, document analysis, instruction-following applications
- Pricing: $0.80-3/million input tokens (Haiku to Sonnet)
- Free credits: No permanent free tier, but $5-10 in credits on new accounts occasionally
- Payment: Credit card required. Same international card considerations apply.
Google Gemini API (Gemini 2.5 Pro and Flash)
- Best for: multimodal apps, Indian language applications, cost-sensitive projects
- Pricing: Free tier with 15 requests/minute and 1,500/day for Gemini 2.5 Flash
- Free credits: Generous free tier makes this the most accessible for Indian developers
- Payment: Free tier requires no payment. Paid tier via Google Cloud billing.
🇮🇳 India Note: For Indian developers on a budget or experimenting, start with Google's Gemini API — the free tier (1,500 requests/day) is large enough for meaningful projects without a credit card. OpenAI and Anthropic require payment info even for free credits.
Getting API Keys
OpenAI:
- Create account at platform.openai.com
- Go to API Keys → Create new secret key
- Copy and store securely (shown only once)
- Add billing: Settings → Billing → Add payment method
- Your $5 free credit is automatically applied
Anthropic:
- Create account at console.anthropic.com
- Go to API Keys → Create Key
- Copy and store securely
- Add billing at Billing → Plan
Google Gemini:
- Go to aistudio.google.com
- Click "Get API key" → Create API key
- Key is created instantly, no billing required for free tier
- Free tier: 15 requests/minute, 1,500 requests/day for Gemini 2.5 Flash
Storing API keys safely: Never put API keys in your code. Use environment variables:
# .env file (never commit this to git)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...
Add .env to .gitignore immediately.
Building a Simple Chatbot in Python
Install the required package:
pip install openai # for OpenAI
# or
pip install anthropic # for Anthropic
# or
pip install google-generativeai # for Gemini
OpenAI chatbot (Python):
from openai import OpenAI
import os
from dotenv import load_dotenv
load_dotenv()
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
def chat(messages: list[dict]) -> str:
response = client.chat.completions.create(
model="gpt-4.1-mini", # cost-effective model
messages=messages,
max_tokens=500
)
return response.choices[0].message.content
# Simple conversation loop
conversation_history = [
{"role": "system", "content": "You are a helpful assistant for Indian students."}
]
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break
conversation_history.append({"role": "user", "content": user_input})
response = chat(conversation_history)
conversation_history.append({"role": "assistant", "content": response})
print(f"Assistant: {response}\n")
Gemini chatbot (Python) — free tier:
import google.generativeai as genai
import os
from dotenv import load_dotenv
load_dotenv()
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
model = genai.GenerativeModel('gemini-2.0-flash')
chat = model.start_chat()
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break
response = chat.send_message(user_input)
print(f"Gemini: {response.text}\n")
Building a Simple Chatbot in Node.js
npm init -y
npm install openai dotenv
OpenAI chatbot (Node.js/TypeScript):
import OpenAI from 'openai';
import * as readline from 'readline';
import * as dotenv from 'dotenv';
dotenv.config();
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const messages: OpenAI.ChatCompletionMessageParam[] = [
{ role: 'system', content: 'You are a helpful assistant for Indian students.' }
];
async function chat(userMessage: string): Promise<string> {
messages.push({ role: 'user', content: userMessage });
const response = await client.chat.completions.create({
model: 'gpt-4.1-mini',
messages,
max_tokens: 500
});
const assistantMessage = response.choices[0].message.content ?? '';
messages.push({ role: 'assistant', content: assistantMessage });
return assistantMessage;
}
// Run in Node.js
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const askQuestion = (question: string) => new Promise<string>(resolve => rl.question(question, resolve));
async function main() {
console.log('Chatbot started. Type "exit" to quit.');
while (true) {
const input = await askQuestion('You: ');
if (input.toLowerCase() === 'exit') { rl.close(); break; }
const response = await chat(input);
console.log(`Assistant: ${response}\n`);
}
}
main().catch(console.error);
Understanding Token Costs
Tokens are how AI APIs measure usage. Roughly:
- 1 token ≈ 4 characters
- 100 tokens ≈ 75 words
- 1,000 tokens ≈ one page of text
Cost examples at current rates:
- Processing a 1,000-word document: ~1,250 tokens input + ~500 tokens output
- Using GPT-5.3 Codex ($0.15/M in, $0.60/M out): ~$0.00048 per document
- Using Gemini Flash (free tier): ₹0 for first 1,500 requests/day
- $5 OpenAI free credit: ~3.3 million input tokens at the cheapest rate
For a personal project processing up to 100 requests/day, costs are negligible. For production applications handling thousands of requests, cost management becomes important.
Budget tips:
- Use the smallest model that meets your quality requirement
- Cache responses for repeated queries
- Truncate input context when the full history is not needed
- Set max_tokens limits to prevent unexpectedly large outputs
💰 Free Deal: Google's Gemini 2.5 Flash has the best free API tier in 2026 — 1,500 requests/day with no credit card. For learning and side projects, this is entirely sufficient. The quality is also excellent for most use cases.
India-Friendly Payment Options
For paid API usage:
- Visa/Mastercard credit cards issued by HDFC, ICICI, Axis, Kotak work for all three providers
- International debit cards with enabled international transactions (most banks offer this)
- Wise (formerly TransferWise) — create a USD virtual card, load from UPI, use for international payments
- Google Cloud credits (for Gemini) can be purchased via Google India channels
Rupay cards currently do not work reliably with US-based API billing systems (as of March 2026).
Official Resources
- OpenAI API Docs — Complete OpenAI API reference
- Anthropic API Docs — Claude API documentation
- Google AI Studio — Gemini API keys and testing
- OpenAI Cookbook — Practical examples and tutorials
- LangChain — Framework for building complex AI applications
Community Questions
0No questions yet. Be the first to ask!