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.
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
| File | Contains | Use For |
|---|---|---|
SKILL.md | Entry point: scope, routing table, and workflow. | Start here. |
docs/counting-tokens-workflow-guide.md | A 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.text | A 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
- Open the most relevant file under
docs/for the exact documented workflow and wording. - Open
schemas/files for exact structured contracts. - Open
examples/files for concrete requests, commands, snippets, and manifests. - 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
