This API provides information about various Large Language Models (LLMs) and their pricing across different providers. The data is maintained by the community to ensure accuracy and timeliness. The API is implemented as a Cloudflare Worker, offering low-latency, serverless execution.
This API is deployed as a Cloudflare Worker, which means:
- Serverless execution with low latency across Cloudflare's global network
- No need to manage servers or infrastructure
- Automatic scaling to handle varying levels of traffic
- Edge computing capabilities for faster response times
https://llm-pricing-api.<your-subdomain>.workers.dev
Replace <your-subdomain>
with the actual Cloudflare subdomain where the worker is deployed.
GET /models
Returns a list of all available LLM models and their providers.
Example request:
curl https://llm-pricing-api.<your-subdomain>.workers.dev/models
Example response:
[
{"name": "gpt-4", "provider": "OpenAI"},
{"name": "claude-3-opus-20240229", "provider": "Anthropic"},
...
]
GET /prices
Calculates the price for a given model based on input and output tokens.
Query Parameters:
provider
: The provider of the model (e.g., OpenAI, Anthropic)model
: The name of the modelinput_tokens
: Number of input tokensoutput_tokens
: Number of output tokens
Example request:
curl "https://llm-pricing-api.<your-subdomain>.workers.dev/prices?provider=OpenAI&model=gpt-4&input_tokens=1000&output_tokens=500"
Example response:
{
"provider": "OpenAI",
"model": "gpt-4",
"input_tokens": 1000,
"output_tokens": 500,
"input_cost": 0.03,
"output_cost": 0.03,
"total_cost": 0.06
}
- OpenAI
- Anthropic
- Groq
- Mistral
The API returns appropriate error messages for invalid requests:
- 400 Bad Request: For invalid provider, model, or token counts
- 404 Not Found: For undefined routes
As this API is deployed on Cloudflare Workers, it is subject to Cloudflare's platform limits:
- Up to 100,000 requests per day on the free plan
- 10ms CPU time per request
- 512MB memory limit
For more details on Cloudflare Workers limits, please refer to the Cloudflare Workers documentation.
As a community-maintained project, we welcome contributions to keep the pricing and model information up-to-date. If you notice any discrepancies or have information about new models, please contribute by submitting a pull request or opening an issue.
- Fork the repository
- Create a new branch for your feature or fix
- Make your changes
- Test your changes locally using wrangler
- Submit a pull request
For major changes, please open an issue first to discuss what you would like to change.
To run this project locally:
- Install wrangler
- Clone this repository
- Rename
wrangler.template.toml
towrangler.toml
and replace theaccount_id
with your Cloudflare account ID - Run
wrangler dev
in the project directory to start a local development server - Make your changes and test them locally
- Deploy your changes using
wrangler publish
For more information or support, please open an issue in this repository.
Made with ❤️ by Latitude
Powered by Cloudflare Workers