DEV Community

Cover image for How to Write Perfect Prompts for GPT-4o & Claude 3.5 Sonnet
Umair Tariq
Umair Tariq

Posted on

How to Write Perfect Prompts for GPT-4o & Claude 3.5 Sonnet

When building LLM wrappers or talking to AI, managing API costs and context limits is all about token counts. But calculating token distributions using standard javascript regex is highly inaccurate.

We integrated the official gpt-tokenizer npm package into a free web utility tool so you can test prompt structures, format system instructions, and get the exact token distribution before sending API calls.

You can calculate tokens and format presets instantly using the free online AI Prompt Helper & Token Counter.

Core Elements of a Perfect Prompt:

  1. Role / Persona: Assigning a specific expert role (e.g. "Act as a Senior React Dev").
  2. Context: Providing details about the target audience and environment.
  3. Specific Task: A clear, actionable request detailing what the AI should write.
  4. Constraints: Restricting what the AI should avoid (e.g. "Do not use external libraries").

Top comments (0)