AI APIs power an incredible range of applications — from simple chatbots to complex document analysis pipelines. This guide covers 15 real-world use cases with production-ready code examples, cost estimates, and model recommendations for each scenario. All examples use Token1.US for unified access to GPT-4o, Claude, DeepSeek-V3, and GLM-4-Plus.
The most common AI API use case. Route customer questions to the cheapest model that handles them well — typically DeepSeek-V3 at $0.14/$0.28 per million tokens.
def customer_service_bot(user_message, context=""):
response = client.chat.completions.create(
model="deepseek-v3", # Cost-efficient for Q&A
messages=[
{"role": "system", "content": "You are a helpful customer service agent..."},
{"role": "user", "content": f"Context: {context}\n\nQuestion: {user_message}"}
],
max_tokens=300
)
return response.choices[0].message.content
Cost: ~$0.001 per conversation (500 input + 200 output tokens on DeepSeek-V3)
Generate long-form content with Claude 3.5 Sonnet for the best writing quality, or DeepSeek-V3 for cost efficiency.
def generate_article(topic, word_count=1000, style="professional"):
response = client.chat.completions.create(
model="claude-3-5-sonnet", # Best writing quality
messages=[
{"role": "system", "content": f"Write a {style} article about {topic}..."},
{"role": "user", "content": f"Write approximately {word_count} words."}
],
max_tokens=2000,
temperature=0.7 # Creative but coherent
)
return response.choices[0].message.content
Cost: ~$0.03 per article on Claude, ~$0.001 on DeepSeek-V3
Build a programming assistant that explains code, suggests fixes, and generates functions. Claude 3.5 Sonnet is the top choice for coding tasks.
def code_assistant(code_snippet, task="explain"):
response = client.chat.completions.create(
model="claude-3-5-sonnet",
messages=[
{"role": "system", "content": "You are an expert programmer. " + task},
{"role": "user", "content": f"```\n{code_snippet}\n```"}
],
max_tokens=1000
)
return response.choices[0].message.content
Condense long documents into concise summaries. Use GLM-4-Plus for a balance of quality and cost.
def summarize(text, max_words=100):
response = client.chat.completions.create(
model="glm-4-plus",
messages=[
{"role": "system", "content": f"Summarize in {max_words} words or less."},
{"role": "user", "content": text}
],
max_tokens=200
)
return response.choices[0].message.content
Classify text sentiment at scale. DeepSeek-V3 is perfect for this — fast, cheap, and accurate for classification tasks.
def analyze_sentiment(text):
response = client.chat.completions.create(
model="deepseek-v3",
messages=[
{"role": "system", "content": "Respond with only: positive, negative, or neutral"},
{"role": "user", "content": text}
],
max_tokens=10,
temperature=0 # Deterministic
)
return response.choices[0].message.content.strip().lower()
Cost: ~$0.0001 per analysis — classify 1 million texts for ~$100
Translate content across languages with GPT-4o for highest accuracy or GLM-4-Plus for Chinese/English tasks.
def translate(text, target_language="Chinese"):
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": f"Translate to {target_language}. Output only the translation."},
{"role": "user", "content": text}
],
max_tokens=1000
)
return response.choices[0].message.content
Combine your knowledge base with AI for accurate, sourced answers. Use Claude's 200K context window for large document sets.
def rag_query(question, relevant_docs):
context = "\n\n".join(relevant_docs)
response = client.chat.completions.create(
model="claude-3-5-sonnet", # 200K context window
messages=[
{"role": "system", "content": "Answer based ONLY on the provided context. If the answer isn't in the context, say so."},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
],
max_tokens=500
)
return response.choices[0].message.content
Automate email composition and responses. DeepSeek-V3 handles routine emails at minimal cost.
def draft_email_reply(incoming_email, tone="professional"):
response = client.chat.completions.create(
model="deepseek-v3",
messages=[
{"role": "system", "content": f"Write a {tone} email reply."},
{"role": "user", "content": f"Original email:\n{incoming_email}\n\nDraft a reply."}
],
max_tokens=300
)
return response.choices[0].message.content
Extract structured data (JSON) from unstructured text using function calling.
def extract_entities(text):
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": f"Extract entities as JSON: {text}"}],
functions=[{
"name": "save_entities",
"parameters": {
"type": "object",
"properties": {
"names": {"type": "array", "items": {"type": "string"}},
"dates": {"type": "array", "items": {"type": "string"}},
"amounts": {"type": "array", "items": {"type": "number"}}
}
}
}],
function_call={"name": "save_entities"}
)
return response.choices[0].message.function_call.arguments
Generate SEO-optimized e-commerce product descriptions from basic specs.
def generate_product_description(product_name, features, keywords):
response = client.chat.completions.create(
model="glm-4-plus", # Good balance of quality and cost
messages=[{
"role": "user",
"content": f"Product: {product_name}\nFeatures: {features}\nSEO keywords: {keywords}\n\nWrite a compelling 150-word product description."
}],
max_tokens=250
)
return response.choices[0].message.content
Generate posts for Twitter/X, LinkedIn, Instagram with platform-specific formatting.
def social_post(topic, platform="twitter"):
limits = {"twitter": 280, "linkedin": 3000, "instagram": 2200}
response = client.chat.completions.create(
model="deepseek-v3",
messages=[{
"role": "user",
"content": f"Write a {platform} post about {topic}. Max {limits.get(platform, 500)} chars."
}],
max_tokens=200
)
return response.choices[0].message.content
Upload PDFs or documents and let users ask questions. Combine with vector search for large document sets.
def document_qa(document_text, question):
response = client.chat.completions.create(
model="gpt-4o", # 128K context for large docs
messages=[
{"role": "system", "content": "Answer questions based on this document."},
{"role": "user", "content": f"Document:\n{document_text[:100000]}\n\nQ: {question}"}
],
max_tokens=500
)
return response.choices[0].message.content
Classify user intents for routing, analytics, or automation workflows.
def classify_intent(user_input):
response = client.chat.completions.create(
model="deepseek-v3",
messages=[
{"role": "system", "content": "Classify intent: purchase, support, info, complaint, other. Respond with one word."},
{"role": "user", "content": user_input}
],
max_tokens=10,
temperature=0
)
return response.choices[0].message.content.strip().lower()
Use GPT-4o's vision capabilities to analyze images, extract text, or describe visual content.
def analyze_image(image_base64, question="Describe this image"):
response = client.chat.completions.create(
model="gpt-4o", # Only model with vision support
messages=[{
"role": "user",
"content": [
{"type": "text", "text": question},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_base64}"}}
]
}],
max_tokens=300
)
return response.choices[0].message.content
Automatically flag inappropriate, spam, or harmful content using AI classification.
def moderate_content(text):
response = client.chat.completions.create(
model="deepseek-v3",
messages=[
{"role": "system", "content": "Classify as: safe, spam, harassment, violence, sexual, hate. Respond with JSON: {category, confidence, reason}"},
{"role": "user", "content": text}
],
max_tokens=100,
temperature=0
)
return response.choices[0].message.content
Don't use GPT-4o for everything. Implement smart routing: use DeepSeek-V3 for 70% of requests (simple tasks), GLM-4-Plus for 20%, and GPT-4o/Claude only for the 10% that truly need premium quality. This can reduce costs by 80-90%.
Cache identical queries. If 1,000 users ask "What is Token1.US?", serve the cached response instead of making 1,000 API calls. Redis or in-memory caching works well.
For bulk tasks, use batch mode instead of streaming. See our streaming vs batch guide for cost comparisons.
Shorten prompts, remove unnecessary context, and set appropriate max_tokens limits. Every token costs money. Read our token pricing guide for optimization strategies.
Ready to build? Get your API key and start with free trial credits.