Prompt Buddy logoPrompt Buddy

openai · OpenAI Platform Docs

Counting tokens

How to use the token counting API to accurately calculate input token usage for various data types including text, conversations, images, files, and tool definitions.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

Counting tokens

How to use the token counting API to accurately calculate input token usage for various data types including text, conversations, images, files, and tool definitions.

When To Use

Use when you need to estimate API costs, optimize prompts for context limits, or route requests based on input size for text, images, files, or tool schemas.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/counting-tokens-workflow-guide.mdA guide explaining how to use the token counting API to estimate input tokens, optimize prompts, and manage context limits.Questions about a guide explaining how to use the token counting API to estimate input tokens, optimize prompts, and manage context l...
examples/counting-tokens-openai-token-counting.textA plain text sample used to demonstrate the token counting process for the OpenAI API.Exact payloads, commands, or snippets shown in A plain text sample used to demonstrate the token counting process for the OpenAI API.

What This Skill Covers

  • Token counting lets you determine how many input tokens a request will use before you send it to the model. Use it to:
  • Main sections: Why use the token counting API?, Count tokens in basic messages, Count tokens in conversations, Count tokens with instructions, Count tokens with images.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://developers.openai.com/api/docs/guides/token-counting.md