Download the PHP package token27/nexus-ai-pricing without Composer
On this page you can find all versions of the php package token27/nexus-ai-pricing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download token27/nexus-ai-pricing
More information about token27/nexus-ai-pricing
Files in token27/nexus-ai-pricing
Package nexus-ai-pricing
Short Description Financial cost calculation for LLM API usage. Supports token-accurate pricing for OpenAI, Anthropic (with Prompt Caching discounts), Google Gemini, DeepSeek, Groq, Mistral, and more.
License MIT
Homepage https://github.com/token27/nexus-ai-pricing
Informations about the package nexus-ai-pricing
nexus-ai-pricing
An extensively engineered, framework-agnostic PHP 8.3+ financial calculation library precisely mapped for LLM API computations. Support inherently covers mathematically accurate pricing for OpenAI, Anthropic, Google Gemini, DeepSeek, Groq, Mistral, and Perplexity — resolving everything from Prompt Caching variants to multimodal image tiles locally.
Why nexus-ai-pricing?
Calculating AI costs is chaotic. OpenAI utilizes a subset caching methodology where read tokens are subtracted from prompt tokens. Anthropic relies on additive cache writes with massive entry surcharges. Gemini alters limits based on context tier tiers and Perplexity adds per-request bounds.
nexus-ai-pricing solves this permanently by:
- Mathematical Accuracy: Handling all floating-point conversions safely without exception flaws.
- Provider-agnostic core: Evaluate cache, images, and text outputs using homogeneous DTOs (
PricingResult). - Zero-Latency Estimations: Utilizing
token27/nexus-ai-tokenizerheavily to count everything strictly offline before issuing network requests. - Graceful Degradation: Safely tags unknown models without triggering fatal system crashes during recursive loops.
Features
- Universal Support: Standard metrics evaluated and natively bundled for ChatGPT, Claude, Gemini, DeepSeek Flash, and more.
- Advanced Caching Mathematics: Separating explicitly standard text costs from cached outputs seamlessly.
- Vision Dimension Math: Evaluates visual inputs correctly processing parameter rules dynamically (Tiles vs Dimensions).
- Chained Price Tables: Override built-in arrays securely via
JsonFilePriceTablestructures explicitly resolving priority overrides. - Glob Pattern Matcher: Registers dynamic limits using wildcard variables (e.g.
gemini-2.1-*) safely. - Type Safety: PHPStan Level 8, completely production-grade testing limits.
Installation
Requires: PHP 8.3+ · token27/nexus-ai-tokenizer ^1.0
Quick Start
1. Post-Request Billing calculation (Using API returned values)
2. Pre-Request Proactive Estimations
3. Multimodal Image Evaluation
4. Custom Image Estimators
All three pricing axes are independently injectable. For proprietary or custom vision models, pass your own ImageTokenEstimatorInterface implementations:
Resolution: the first estimator whose supports($model) returns true wins. When imageEstimators is empty (the default), all three built-in estimators are used automatically.
Documentation
- Getting Started — Cost calculations and quick one-liners
- Installation Setup — Composer, requirements, and DI container setup
- Architecture Schematic — Core concepts, pricing engine flows and data structures
- Pricing Engine Rules — Class APIs, estimate methods, and facades
- Pricing Result Typings — Returned metrics, DTOs, and standard formatting
- Caching Strategies — Anthropic Additive Logic vs OpenAI Subset bounds
- Multimodal Vision Pricing — Image complexities, tiles, constraints, custom image estimators
- Custom Price Tables — Decorating interfaces using external JSON arrays
- Pricing Registry — Factory instantiation, memory safety
- Advanced Integration — Immutable recursive iteration
- Examples Guide — Directory map against all 8 baseline examples
- Default Internal Catalog — Complete parameter specifications
- System Internals — Math limits and unknown models
- Testing & Validation — PHPUnit, CS-Fixer and logic overrides
- Contributing Guidelines — Safe repository upgrades
License
MIT. See LICENSE.