{"id":25735962,"url":"https://github.com/ableinc/prompt-token-count","last_synced_at":"2026-04-18T10:37:20.087Z","repository":{"id":279274871,"uuid":"938276096","full_name":"ableinc/prompt-token-count","owner":"ableinc","description":"Tokenize a prompt and/or get the number of tokens a prompt will take","archived":false,"fork":false,"pushed_at":"2025-02-25T16:22:39.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T00:25:05.379Z","etag":null,"topics":["ai","chat-gpt","gpt","llm","openai","token-count","tokenizer"],"latest_commit_sha":null,"homepage":"https://github.com/ableinc/prompt-token-count","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ableinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-24T17:40:33.000Z","updated_at":"2025-02-25T16:21:16.000Z","dependencies_parsed_at":"2025-10-05T00:18:25.578Z","dependency_job_id":"7ef9267d-b597-42a4-83bf-3589069ce342","html_url":"https://github.com/ableinc/prompt-token-count","commit_stats":null,"previous_names":["ableinc/prompt-token-count"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ableinc/prompt-token-count","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fprompt-token-count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fprompt-token-count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fprompt-token-count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fprompt-token-count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ableinc","download_url":"https://codeload.github.com/ableinc/prompt-token-count/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ableinc%2Fprompt-token-count/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31966206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chat-gpt","gpt","llm","openai","token-count","tokenizer"],"created_at":"2025-02-26T05:34:35.786Z","updated_at":"2026-04-18T10:37:20.048Z","avatar_url":"https://github.com/ableinc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prompt Token Count\n\nTokenize a prompt and/or get the number of tokens a prompt will take\n\n## Install\n\n```bash\ngo get github.com/ableinc/prompt-token-count\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/ableinc/prompt-token-count/cmd/tokenizer\"\n)\n\nfunc encodingForModel(model string) (*tokenizer.Encoding, error) {\n\tswitch model {\n\tcase \"gpt-4\", \"gpt-4-turbo\", \"gpt-3.5-turbo\", \"text-embedding-ada-002\":\n\t\treturn tokenizer.GetEncoding(\"cl100k_base\")\n\tcase \"gpt-4o\", \"gpt-4o-mini\":\n\t\treturn tokenizer.GetEncoding(\"o200k_base\")\n\tcase \"text-davinci-002\", \"text-davinci-003\", \"code-davinci-002\", \"text-davinci-edit-001\":\n\t\treturn tokenizer.GetEncoding(\"p50k_base\")\n\tcase \"code-cushman-001\", \"davinci\", \"curie\", \"babbage\", \"ada\":\n\t\treturn tokenizer.GetEncoding(\"r50k_base\")\n\tcase \"text-ada-001\", \"text-babbage-001\", \"text-curie-001\", \"text-davinci-001\", \"code-davinci-001\":\n\t\treturn tokenizer.GetEncoding(\"gpt2\")\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown model: %s\", model)\n\t}\n}\n\nfunc main() {\n\tmodel, err := encodingForModel(\"gpt-4\")\n\tif err != nil {\n\t\tlog.Fatalf(\"incorrect model provided: %v\", err)\n\t}\n\tprompt := tokenizer.TokenString(\"Give me Golang code to create a binary tree.\")\n\tfmt.Println(\"Number of tokens (raw text): \", prompt.CountTokens())\n\ttokens := model.Encode(prompt)\n\tfmt.Println(\"NUmber of tokens (encodings): \", tokens.CountTokens())\n\tfmt.Println(\"Encoding: \", tokens)\n\tprompt = model.Decode(tokens)\n\tfmt.Println(\"Decoding: \", prompt)\n}\n```\n\n## Input/Output Cost?\n\nIf you need to know the cost for a prompt (input) and the output (completion) use this library: [prompt-complete-cost](https://github.com/ableinc/prompt-complete-cost)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fableinc%2Fprompt-token-count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fableinc%2Fprompt-token-count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fableinc%2Fprompt-token-count/lists"}