Back to Templates

Cost based Ratelimiting

Ratelimit your AI application based on estimated cost

Written by
hashsbhat
Framework
Next.js
Language
Typescript
Ratelimit your AI application based on estimated cost

Cost-based rate limiting API

Overview

This is a JSON processing service that transforms unstructured data into well-structured JSON using OpenAI 3.5 turbo and gpt4

Check it out here

Ratelimits

  • We use Unkey for rate-limiting

  • /api/json uses gpt-4 ( 2 request limit per 30 seconds )

  • /api/jsonCheap uses gpt-turbo-3.5 ( 4 request limit per 30 seconds )

Prerequisites

Unkey

OpenAI API

Upstash Redis (Optional as we just keep track of total requests using this)

Setup Unkey

  1. Go to unkey ratelimits

  2. Create a new namespace with name harshbhat

  3. Go to settings/root-keys and create a root key with Ratelimit permissions

  4. Add it in the .env file UNKEY_ROOT_KEY

Installation

  1. Clone the repository:

    1git clone https://github.com/harshsbhat/ordox.git
    2cd ordox
  2. Setup .env files cp .env.example .env

    MANDATORY:

    1OPENAI_API_KEY=""
    2UNKEY_ROOT_KEY=""

    OPTIONAL:

    1 UPSTASH_REDIS_REST_URL=""
    2 UPSTASH_REDIS_REST_TOKEN=""
  3. Install dependencies and run the project it should start on port 3000

    1pnpm i
    2pnpm dev

Usage

You can use https://ordox.vercel.app/api/json to convert your Unstructured data into JSON using OpenAI gpt-4 model. Although it has a limit of 2 requests per 30 seconds

You can use https://ordox.vercel.app/api/json to convert your Unstructured data into JSON using OpenAI gpt-3.5-turbo model. This one has a limit of 4 requests per 30 seconds

License

This project is licensed under the MIT License - see the LICENSE file for details.

Protect your API.
Start today.

2500 verifications and 100K successful rate‑limited requests per month. No CC required.