
"AI Prompt Engineering Best Practices: The Developer's Guide for 2026"
The difference between a mediocre AI response and a brilliant one often comes down to how you ask. Prompt engineering — the practice of crafting inputs that guide large language models toward desired outputs — has become a core developer skill in 2026. Whether you're building chatbots, automating workflows, or generating code, the quality of your prompts directly determines the quality of your results.
This guide covers the techniques that actually work across GPT-5, Claude Opus, and Gemini 3 Pro, with real API code examples you can use today.
Why Prompt Engineering Matters#
LLMs are powerful but literal. They respond to what you write, not what you mean. A vague prompt produces a vague answer. A structured, specific prompt produces structured, specific output. For developers integrating AI into production systems, this isn't optional — it's the difference between a reliable feature and a random text generator.
The good news: prompt engineering follows learnable patterns. Master a handful of core techniques and you'll get dramatically better results from any model.
Core Techniques#
Zero-Shot Prompting#
The simplest approach — give the model a task with no examples. Works well for straightforward requests where the model already has strong training data.
Classify the following customer message as "billing", "technical", or "general":
Message: "I can't log into my account after changing my password"
Category:
Best for: simple classification, summarization, translation.
Few-Shot Prompting#
Provide 2-5 examples before your actual query. This dramatically improves accuracy for tasks where the model needs to understand your specific format or criteria.
Convert these product descriptions to JSON:
Input: "Red cotton t-shirt, size L, $29.99"
Output: {"color": "red", "material": "cotton", "type": "t-shirt", "size": "L", "price": 29.99}
Input: "Blue denim jacket, size M, $89.00"
Output: {"color": "blue", "material": "denim", "type": "jacket", "size": "M", "price": 89.00}
Input: "Black leather boots, size 10, $149.50"
Output:
Chain-of-Thought (CoT)#
Ask the model to reason step-by-step before giving a final answer. This is essential for math, logic, and complex analysis tasks.
A store has 150 items. 40% are electronics, and 25% of electronics are on sale.
How many electronics are on sale?
Think step by step:
Adding "Think step by step" or "Let's work through this" can improve accuracy on reasoning tasks by 20-40%.
Role Prompting#
Assign the model a specific persona or expertise. This activates relevant knowledge patterns and adjusts the response style.
You are a senior security engineer reviewing code for vulnerabilities.
Analyze the following Python function and identify any security issues:
Model-Specific Tips#
GPT-5 (OpenAI)#
- Excels at following complex multi-step instructions
- Use
response_format: { type: "json_object" }for reliable JSON output - System messages carry strong weight — put your core instructions there
- Supports function calling natively for structured tool use
Claude Opus (Anthropic)#
- Handles very long contexts well (200K tokens)
- Responds well to XML-tagged sections in prompts (
<instructions>,<context>,<examples>) - Tends to be more cautious — be explicit when you want direct answers
- Strong at following nuanced, detailed instructions
Gemini 3 Pro (Google)#
- Native multimodal — can process images, audio, and video in prompts
- Strong at grounding responses in provided documents
- Use structured prompts with clear section headers
- Good at code generation across many languages
Structured Output Techniques#
JSON Mode via API#
Here's how to get reliable JSON output using Python with the OpenAI-compatible API:
import openai
client = openai.OpenAI(
base_url="https://crazyrouter.com/v1",
api_key="your-crazyrouter-key"
)
response = client.chat.completions.create(
model="gpt-5",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Extract product info as JSON with fields: name, price, category."},
{"role": "user", "content": "The new AirPods Pro 3 cost $279 and fall under audio accessories."}
]
)
print(response.choices[0].message.content)
# {"name": "AirPods Pro 3", "price": 279, "category": "audio accessories"}
Function Calling#
Function calling lets you define a schema the model must follow:
tools = [{
"type": "function",
"function": {
"name": "create_ticket",
"description": "Create a support ticket from customer message",
"parameters": {
"type": "object",
"properties": {
"category": {"type": "string", "enum": ["billing", "technical", "general"]},
"priority": {"type": "string", "enum": ["low", "medium", "high"]},
"summary": {"type": "string"}
},
"required": ["category", "priority", "summary"]
}
}
}]
response = client.chat.completions.create(
model="claude-opus-4",
messages=[{"role": "user", "content": "My payment failed and I'm locked out!"}],
tools=tools
)
Node.js Example#
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://crazyrouter.com/v1",
apiKey: "your-crazyrouter-key",
});
const response = await client.chat.completions.create({
model: "gemini-3-pro",
messages: [
{
role: "system",
content: `You are a code reviewer. Analyze the code and respond with JSON:
{"issues": [{"severity": "high|medium|low", "line": number, "description": "..."}]}`
},
{ role: "user", content: "def login(user, pwd):\n query = f'SELECT * FROM users WHERE name={user}'" }
],
response_format: { type: "json_object" },
});
console.log(JSON.parse(response.choices[0].message.content));
cURL Example#
curl -X POST https://crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-crazyrouter-key" \
-d '{
"model": "gpt-5",
"messages": [
{"role": "system", "content": "You are a helpful assistant. Use chain-of-thought reasoning."},
{"role": "user", "content": "Compare the time complexity of quicksort vs mergesort. Which should I use for a nearly-sorted array of 10M elements?"}
],
"temperature": 0.3
}'
Testing Prompts Across Models with Crazyrouter#
One of the biggest challenges in prompt engineering is that different models respond differently to the same prompt. A prompt optimized for GPT-5 might underperform on Claude, and vice versa.
Crazyrouter solves this by providing a single OpenAI-compatible API that routes to 300+ models. You can test the same prompt across GPT-5, Claude Opus, Gemini 3 Pro, DeepSeek, and more — just change the model parameter. No need to manage multiple API keys or SDKs.
models = ["gpt-5", "claude-opus-4", "gemini-3-pro", "deepseek-v3"]
for model in models:
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": your_prompt}],
temperature=0.3
)
print(f"{model}: {response.choices[0].message.content[:100]}")
This makes A/B testing prompts across models trivial — essential for finding the best model-prompt combination for your use case.
Pricing Comparison#
When testing prompts across models, cost matters. Here's how major models compare:
| Model | Official Input (per 1M tokens) | Official Output (per 1M tokens) | Crazyrouter Input | Crazyrouter Output |
|---|---|---|---|---|
| GPT-5 | $10.00 | $30.00 | $3.00 | $9.00 |
| Claude Opus 4 | $15.00 | $75.00 | $4.50 | $22.50 |
| Gemini 3 Pro | $7.00 | $21.00 | $2.10 | $6.30 |
| DeepSeek V3 | $0.27 | $1.10 | $0.14 | $0.55 |
Crazyrouter typically offers 50-70% savings compared to official API pricing. Check crazyrouter.com for current rates.
Common Mistakes to Avoid#
- Being too vague — "Write something about marketing" vs "Write a 200-word LinkedIn post about B2B SaaS marketing trends in 2026, targeting CTOs"
- Ignoring temperature settings — Use low temperature (0.1-0.3) for factual/structured tasks, higher (0.7-1.0) for creative work
- Overloading a single prompt — Break complex tasks into multiple API calls rather than cramming everything into one prompt
- Not using system messages — The system role is specifically designed for persistent instructions; use it
- Skipping output format specification — Always tell the model exactly what format you want (JSON, markdown, bullet points, etc.)
- Testing on only one model — Different models have different strengths; test across providers to find the best fit
FAQ#
What is prompt engineering?#
Prompt engineering is the practice of designing and optimizing inputs (prompts) for AI language models to produce accurate, relevant, and useful outputs. It involves techniques like few-shot learning, chain-of-thought reasoning, and structured formatting to guide model behavior.
Which AI model is best for prompt engineering in 2026?#
There's no single best model — it depends on your task. GPT-5 excels at instruction following and function calling. Claude Opus handles long documents and nuanced analysis. Gemini 3 Pro is strongest for multimodal tasks. Use a unified API like Crazyrouter to test across all of them.
How do I get consistent JSON output from LLMs?#
Use the response_format: { type: "json_object" } parameter (supported by most models via OpenAI-compatible APIs), include a JSON schema in your system prompt, or use function calling to enforce a specific output structure.
Does prompt engineering work the same across all models?#
No. Each model family has different strengths and quirks. Claude responds well to XML tags, GPT-5 follows system messages closely, and Gemini handles multimodal inputs natively. Always test your prompts across models before deploying to production.
What temperature should I use for different tasks?#
Use 0.0-0.3 for factual extraction, classification, and structured output. Use 0.5-0.7 for balanced tasks like summarization. Use 0.8-1.0 for creative writing, brainstorming, and generating diverse options.
How many few-shot examples should I include?#
For most tasks, 2-5 examples are sufficient. More examples improve consistency but increase token usage and cost. Start with 3 examples and adjust based on output quality.
Can I use the same API key to test prompts on different models?#
Yes — services like Crazyrouter provide a single API key that works across 300+ models from OpenAI, Anthropic, Google, DeepSeek, and more. Just change the model parameter in your API call.
Summary#
Prompt engineering in 2026 is about precision, structure, and testing. Master the core techniques — zero-shot, few-shot, chain-of-thought, and role prompting — then adapt them for each model's strengths. Use structured output modes and function calling for production reliability. Most importantly, test your prompts across multiple models to find the optimal combination.
Ready to start testing? Crazyrouter gives you one API key for 300+ models at up to 70% off official pricing — the fastest way to iterate on your prompts across GPT-5, Claude, Gemini, DeepSeek, and more.


