Spaces:
Sleeping
Sleeping
| """ | |
| AI API Cost Calculator 2026 — NexaAPI vs All Major Providers | |
| Compare costs for Image Generation, LLM, TTS, Video APIs | |
| """ | |
| import gradio as gr | |
| # Pricing data (per unit) — verified March 2026 | |
| PRICING = { | |
| "Image Generation (per image)": { | |
| "NexaAPI 🏆": 0.003, | |
| "OpenAI DALL-E 3": 0.040, | |
| "Stability AI": 0.020, | |
| "Replicate": 0.015, | |
| "FAL.ai": 0.012, | |
| "DeepAI": 0.010, | |
| }, | |
| "LLM (per 1M tokens)": { | |
| "NexaAPI 🏆": 0.50, | |
| "OpenAI GPT-4o": 5.00, | |
| "Anthropic Claude 3.5": 3.00, | |
| "Google Gemini 1.5 Pro": 3.50, | |
| "Together AI": 1.00, | |
| "Replicate": 2.00, | |
| }, | |
| "Text-to-Speech (per 1M chars)": { | |
| "NexaAPI 🏆": 1.00, | |
| "ElevenLabs": 22.00, | |
| "OpenAI TTS": 15.00, | |
| "Google TTS": 4.00, | |
| "Azure TTS": 4.00, | |
| "Amazon Polly": 4.00, | |
| }, | |
| "Video Generation (per second)": { | |
| "NexaAPI 🏆": 0.05, | |
| "Runway ML": 0.50, | |
| "Pika Labs": 0.40, | |
| "Kling AI": 0.30, | |
| "Sora (OpenAI)": 0.60, | |
| "Replicate": 0.35, | |
| }, | |
| } | |
| SAVINGS_TIPS = { | |
| "Image Generation (per image)": "💡 NexaAPI saves you **87% vs OpenAI DALL-E 3** — generate 13x more images for the same budget!", | |
| "LLM (per 1M tokens)": "💡 NexaAPI saves you **90% vs GPT-4o** — run 10x more LLM calls without increasing your budget!", | |
| "Text-to-Speech (per 1M chars)": "💡 NexaAPI saves you **95% vs ElevenLabs** — same quality voices at a fraction of the cost!", | |
| "Video Generation (per second)": "💡 NexaAPI saves you **90% vs Runway ML** — create 10x more AI video content for the same price!", | |
| } | |
| def calculate_costs(api_type, quantity): | |
| """Calculate and compare costs across providers.""" | |
| if quantity <= 0: | |
| return "Please enter a quantity greater than 0.", "" | |
| prices = PRICING[api_type] | |
| results = [] | |
| # Unit label | |
| unit_labels = { | |
| "Image Generation (per image)": "images", | |
| "LLM (per 1M tokens)": "M tokens", | |
| "Text-to-Speech (per 1M chars)": "M characters", | |
| "Video Generation (per second)": "seconds of video", | |
| } | |
| unit = unit_labels[api_type] | |
| results.append(f"## 💰 Cost Comparison for {quantity:,} {unit}\n") | |
| results.append("| Provider | Cost | vs NexaAPI |") | |
| results.append("|----------|------|------------|") | |
| nexa_cost = prices["NexaAPI 🏆"] * quantity | |
| for provider, price_per_unit in sorted(prices.items(), key=lambda x: x[1]): | |
| total_cost = price_per_unit * quantity | |
| if provider == "NexaAPI 🏆": | |
| results.append(f"| **{provider}** | **${total_cost:.2f}** | ✅ Cheapest! |") | |
| else: | |
| multiplier = total_cost / nexa_cost | |
| savings = total_cost - nexa_cost | |
| results.append(f"| {provider} | ${total_cost:.2f} | {multiplier:.1f}x more expensive (+${savings:.2f}) |") | |
| results.append(f"\n{SAVINGS_TIPS[api_type]}") | |
| results.append(f"\n### 🚀 Start Saving Today") | |
| results.append(f"- 🌐 **Website**: [nexa-api.com](https://nexa-api.com)") | |
| results.append(f"- 📦 **PyPI**: [pip install nexaapi](https://pypi.org/project/nexaapi)") | |
| results.append(f"- 📦 **npm**: [npm install nexaapi](https://npmjs.com/package/nexaapi)") | |
| results.append(f"- 🔗 **RapidAPI**: [rapidapi.com/user/nexaquency](https://rapidapi.com/user/nexaquency)") | |
| results.append(f"\n> **100 free generations** — no credit card required!") | |
| # Summary card | |
| summary = f"**NexaAPI Cost: ${nexa_cost:.2f}**\nYou save up to ${(max(prices.values()) - prices['NexaAPI 🏆']) * quantity:.2f} vs the most expensive provider!" | |
| return "\n".join(results), summary | |
| def get_quick_comparison(api_type): | |
| """Get a quick price table for the selected API type.""" | |
| prices = PRICING[api_type] | |
| nexa_price = prices["NexaAPI 🏆"] | |
| lines = [f"### {api_type} — Price per Unit\n"] | |
| for provider, price in sorted(prices.items(), key=lambda x: x[1]): | |
| bar = "🟢" if provider == "NexaAPI 🏆" else "🔴" if price > nexa_price * 5 else "🟡" | |
| lines.append(f"{bar} **{provider}**: ${price:.4f}") | |
| return "\n".join(lines) | |
| # Build the Gradio interface | |
| with gr.Blocks( | |
| title="AI API Cost Calculator 2026 — NexaAPI vs All Providers", | |
| theme=gr.themes.Soft(), | |
| css=""" | |
| .header { text-align: center; padding: 20px; } | |
| .cta-box { background: #f0f9ff; border: 2px solid #0ea5e9; border-radius: 8px; padding: 15px; margin: 10px 0; } | |
| """ | |
| ) as demo: | |
| gr.Markdown(""" | |
| # 💰 AI API Cost Calculator 2026 | |
| ## NexaAPI vs OpenAI vs ElevenLabs vs Replicate vs FAL.ai | |
| **Find out how much you're overpaying for AI APIs — and how much you could save with NexaAPI.** | |
| > 🏆 NexaAPI offers **56+ AI models** (Image, LLM, TTS, Video) at the **lowest prices** in 2026. | |
| > Start with **100 free generations** — no credit card required! | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### ⚙️ Configure Your Usage") | |
| api_type = gr.Dropdown( | |
| choices=list(PRICING.keys()), | |
| value="Image Generation (per image)", | |
| label="API Type", | |
| info="Select the type of AI API you want to compare" | |
| ) | |
| quantity = gr.Number( | |
| value=1000, | |
| label="Monthly Usage (units)", | |
| info="Enter your expected monthly usage", | |
| minimum=1, | |
| maximum=10000000, | |
| step=100 | |
| ) | |
| calculate_btn = gr.Button("🔢 Calculate Costs", variant="primary", size="lg") | |
| quick_prices = gr.Markdown(label="Quick Price Reference") | |
| with gr.Column(scale=2): | |
| gr.Markdown("### 📊 Cost Comparison Results") | |
| summary_output = gr.Markdown(label="Summary") | |
| results_output = gr.Markdown(label="Detailed Comparison") | |
| gr.Markdown(""" | |
| --- | |
| ## 🚀 Why Choose NexaAPI? | |
| | Feature | NexaAPI | OpenAI | ElevenLabs | Replicate | | |
| |---------|---------|--------|------------|-----------| | |
| | **Image Generation** | $0.003/img | $0.04/img | ❌ | $0.015/img | | |
| | **LLM Access** | $0.50/1M tok | $5.00/1M tok | ❌ | $2.00/1M tok | | |
| | **Text-to-Speech** | $1.00/1M chars | $15.00/1M chars | $22.00/1M chars | ❌ | | |
| | **Video Generation** | $0.05/sec | $0.60/sec | ❌ | $0.35/sec | | |
| | **Free Tier** | ✅ 100 free | Limited | Limited | Limited | | |
| | **Models Available** | 56+ | 10+ | 30+ | 100+ | | |
| | **OpenAI Compatible** | ✅ Yes | ✅ Yes | ❌ | ❌ | | |
| ### 📦 Quick Start (3 lines of code!) | |
| ```python | |
| pip install nexaapi | |
| ``` | |
| ```python | |
| import nexaapi | |
| # Image Generation — 13x cheaper than DALL-E 3 | |
| result = nexaapi.image.generate("A beautiful sunset over mountains") | |
| # LLM — 10x cheaper than GPT-4o | |
| response = nexaapi.chat.complete("Explain quantum computing") | |
| # TTS — 22x cheaper than ElevenLabs | |
| audio = nexaapi.tts.generate("Hello, world!", voice="nova") | |
| ``` | |
| ### 🔗 Links | |
| - 🌐 [nexa-api.com](https://nexa-api.com) — Official Website | |
| - 📦 [PyPI: nexaapi](https://pypi.org/project/nexaapi) — Python Package | |
| - 📦 [npm: nexaapi](https://npmjs.com/package/nexaapi) — JavaScript Package | |
| - 🔗 [RapidAPI](https://rapidapi.com/user/nexaquency) — API Marketplace | |
| """) | |
| # Event handlers | |
| api_type.change( | |
| fn=get_quick_comparison, | |
| inputs=[api_type], | |
| outputs=[quick_prices] | |
| ) | |
| calculate_btn.click( | |
| fn=calculate_costs, | |
| inputs=[api_type, quantity], | |
| outputs=[results_output, summary_output] | |
| ) | |
| # Initialize quick prices on load | |
| demo.load( | |
| fn=get_quick_comparison, | |
| inputs=[api_type], | |
| outputs=[quick_prices] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |