{"categories":[{"label":"Artificial Intelligence","url":"https://skillfed.io/packages/category/scientific-engineering-artificial-intelligence/11"}],"enrichment":{"capability":"Estimates token usage for OpenAI Chat Completions API messages and builds message lists that fit within model token limits, accounting for text, images, tools, and few-shot examples.","skillfed_tags":["openai-integration","token-accounting","llm-utilities"],"use_cases":["Automatically truncate chat history to fit within a model's context window before sending to the OpenAI API.","Calculate token costs for images in GPT-4 vision requests to budget vision-enabled conversations.","Build few-shot prompts with known token budgets, ensuring examples fit alongside user messages.","Estimate API costs by counting tokens before making requests to OpenAI.","Handle tool definitions and tool-choice parameters in token calculations for function-calling workflows."],"what_it_does":"This package wraps OpenAI's tokenization logic to help you stay within token budgets when building chat conversations. It provides functions to count tokens in individual messages, images (for GPT-4 vision), and tool definitions, then uses those counts to automatically truncate old messages from a conversation history so the final message list fits within a model's token limit.\n\nYou supply a system prompt, optional few-shot examples, past messages, and a new user message, along with a target token budget and model name. The library calculates the token cost of each component using tiktoken for text and Pillow for image dimensions, then drops old messages from the history until everything fits. It also supports Azure OpenAI model names and can fall back to default limits if a model is unrecognized.","worth_installing":"Yes, if you are building applications that use OpenAI's Chat Completions API and need to manage token budgets programmatically. The library is straightforward, has low install friction, carries no known vulnerabilities, and solves a real operational problem\u2014preventing token-limit errors by pre-calculating and truncating conversations. Maintenance is aging but the repository is active; use it with the understanding that updates may be infrequent."},"id":"openai-messages-token-helper","links":{"html":"https://skillfed.io/packages/openai-messages-token-helper","md":"https://skillfed.io/packages/openai-messages-token-helper.md","pypi":"https://pypi.org/project/openai-messages-token-helper/"},"maintenance":{"status":"aging"},"meta":{"latest_release":"2025-12-29","license_spdx":null,"license_treatment":"permissive","name":"openai-messages-token-helper","python_support":"supports_current","summary":"A helper library for estimating tokens used by messages sent through OpenAI Chat Completions API."},"popularity":{"monthly_downloads":86761,"position":13840,"tier":"top_15000"},"security":{"n_vulnerabilities":0},"version":"0.1.13"}
