Skip to main content

Static token limits for Azure OpenAI models (context/output), with CLI.

Project description

Azure OpenAI Limits

A Python package that provides static token limits for Azure OpenAI models, including context and output limits for various model versions.

Installation

pip install azure-openai-limits

Usage

Python API

from azure_openai_limits import get_limits, context_limit, output_limit

# Get limits for a model (uses default version)
limits = get_limits("gpt-4o")
print(f"Context: {limits.context}, Output: {limits.output}")

# Get limits for a specific version
limits = get_limits("gpt-4o", "2024-05-13")
print(f"Context: {limits.context}, Output: {limits.output}")

# Try the new O3 Pro model
limits = get_limits("o3-pro")
print(f"O3 Pro - Context: {limits.context}, Output: {limits.output}")

# Check Codex Mini limits
limits = get_limits("codex-mini")
print(f"Codex Mini - Context: {limits.context}, Output: {limits.output}")

# Get just context or output limits
context = context_limit("gpt-4o")
output = output_limit("gpt-4o")

# Check if a model/version exists
from azure_openai_limits import model_exists
if model_exists("gpt-4o", "2024-08-06"):
    print("Model version exists!")

# List all available models
from azure_openai_limits import list_models
models = list_models()
print("Available models:", models)

# List all versions for a model
from azure_openai_limits import list_versions
versions = list_versions("gpt-4o")
print("Available versions:", versions)

Command Line Interface

# List all available models and their versions
azure-openai-limits list

# Show limits for a specific model (default version)
azure-openai-limits show gpt-4o

# Show limits for a specific model version
azure-openai-limits show gpt-4o --version 2024-05-13

# Check out the new O3 Pro model
azure-openai-limits show o3-pro

Supported Models

The package includes limits for the following Azure OpenAI models:

  • Codex: codex-mini
  • GPT-3.5: gpt-35-turbo, gpt-35-turbo-instruct
  • GPT-4: gpt-4, gpt-4-32k
  • GPT-4.1: gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
  • GPT-4o: gpt-4o, gpt-4o-mini
  • GPT-4o Audio: gpt-4o-audio-preview, gpt-4o-mini-audio-preview
  • GPT-4o Realtime: gpt-4o-realtime-preview, gpt-4o-mini-realtime-preview
  • GPT-5: gpt-5, gpt-5-mini, gpt-5-nano, gpt-5-chat, gpt-5-pro, gpt-5-codex
  • GPT-5.1: gpt-5.1, gpt-5.1-chat, gpt-5.1-codex, gpt-5.1-codex-mini, gpt-5.1-codex-max
  • GPT-5.2: gpt-5.2, gpt-5.2-chat
  • GPT-5.3: gpt-5.3-chat, gpt-5.3-codex
  • GPT-5.4: gpt-5.4, gpt-5.4-pro
  • GPT OSS: gpt-oss-20b, gpt-oss-120b
  • O1 Models: o1, o1-mini, o1-preview
  • O3 Models: o3, o3-mini, o3-pro
  • O4 Models: o4-mini
  • Model Router: model-router

Each model may have multiple versions with different limits. Use azure-openai-limits list to see all available models and their versions.

Data Source

The model limits data in this package is sourced from the official Microsoft documentation: Azure AI Foundry OpenAI Models

Last Updated: March 16, 2026

API Reference

Classes

Limits

A dataclass representing token limits for a model.

Attributes:

  • context: int - Maximum context tokens (input + conversation history)
  • output: int - Maximum output tokens that can be generated
  • total_max: int - Property returning context + output

Functions

get_limits(model: str, version: str | None = None) -> Limits

Get context and output limits for a specific model.

context_limit(model: str, version: str | None = None) -> int

Get just the context limit for a model.

output_limit(model: str, version: str | None = None) -> int

Get just the output limit for a model.

model_exists(model: str, version: str | None = None) -> bool

Check if a model (and optionally version) exists.

list_models() -> list[str]

Get a sorted list of all available model names.

list_versions(model: str) -> list[str]

Get a sorted list of all versions for a specific model.

all_models() -> dict[str, dict[str, Limits]]

Get the complete model data structure.

Error Handling

The package raises appropriate exceptions:

  • KeyError: When a model or version is not found
  • ValueError: When invalid input is provided (e.g., empty model name)

All error messages include helpful information about available models/versions.

Development

To set up for development:

git clone <repository-url>
cd azure-openai-limits
pip install -e ".[dev]"

Run tests:

pytest

Run linting:

ruff check src/
mypy src/

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_openai_limits-0.1.6.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_openai_limits-0.1.6-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file azure_openai_limits-0.1.6.tar.gz.

File metadata

  • Download URL: azure_openai_limits-0.1.6.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for azure_openai_limits-0.1.6.tar.gz
Algorithm Hash digest
SHA256 980ec25afdebff5c6bc38d4fcaa69b1920ea8a7c581b9d8a735ab6ef912ab0cc
MD5 78cf9e0bfc9b2131b40169554f5f8a86
BLAKE2b-256 8ba68a603438923ed3aa3abc0886dd231811a44652f6bedf9dc7803ec12463fd

See more details on using hashes here.

File details

Details for the file azure_openai_limits-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: azure_openai_limits-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for azure_openai_limits-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 00542f2f72f03f41ac19c6fa9ecf8e11b260779601a96aeaaacca2ea4a5d4959
MD5 361ae1ea928a5028c2f65fa629f0fc08
BLAKE2b-256 83de8793d4eb70a82f3f507fa26d7e811e87a4678f3cdc1a1e5e9b022d8827f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page