Free API-based LLM Cascade Library
A Python library for cascading LLM (Large Language Model) API calls, allowing you to leverage multiple providers for enhanced language processing capabilities.
Features
- Supports multiple LLM providers (e.g., Groq, Google AI, SambaNova, OpenRouter).
- Easy-to-use interface for making API calls.
- Cosine similarity calculations for comparing responses.
- Environment variable management for sensitive API keys.
Installation
To install the library, you can use pip:
pip install free-apis-llm-cascade
Environment Variables
Before using the library, you need to set up your API keys. Create a .env file in the root directory of your project and populate it with your API keys as follows:
.env
GROQ_API_KEY=your_groq_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
SAMBANOVA_API_KEY=your_sambanova_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
Make sure to replace the placeholder values with your actual API keys.
Usage
Here’s a quick example of how to use the LLMCascade class:
from free_apis_llm_cascade.cascade import LLMCascade
import asyncio
async def main():
# Instantiate the LLMCascade class
llm_cascade = LLMCascade()
# Prepare your messages, vendors, and models to test the cascade with as well as the cosine similarity threshold
messages=[{ "role": "user", "content": "What is the capital of California?" }]
vendors = ["sambanova", "openrouter", "groq", "groq"] # these are the vendors for the models below
models = ["Meta-Llama-3.2-1B-Instruct", "meta-llama/llama-3.2-3b-instruct:free", "llama3-8b-8192", "llama-3.3-70b-versatile"] # these are the actual models that will be run
# call the llm cascade function
output, num_models_run = await llm_cascade.cascade_three_or_more_llm(vendors, models, messages, 0.7) # cosine threshold = 0.7 here
print(40*"-")
print(f"Final result: {output}")
print(f"Models run up to: {models[num_models_run-1]}")
# Run the main function
if name == "main":
asyncio.run(main())
The three functions that are usable in this library currently are:
get_single_model_result(self, vendor, model, messages)
cosine_sim_two_llm_basic(self, vendors, models, input)
cascade_three_or_more_llm(self, vendors, models, input, cos_sim_threshold)
Contributing
Contributions are welcome! If you have suggestions for improvements or find bugs, please open an issue or submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Useful reference
This GitHub repo stores information about what free LLM APIs are available. We currently only support Groq, Google AI Studio, SambaNova, and OpenRouter, but may expand to others soon.
Metadata
Release files for free-apis-llm-cascade 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| free_apis_llm_cascade-0.3.2.tar.gz | 50.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| free_apis_llm_cascade-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.4 kB
Release files / free_apis_llm_cascade-0.3.2.tar.gz
| Download URL | free_apis_llm_cascade-0.3.2.tar.gz |
|---|---|
| Size | 50.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20d281879bf270a1dfae5852e592e9375fbf304c7e2160de687e70e379a0db03
|
|
BLAKE2b-256 checksum How to use checksums |
1f5ea38ceb7c89121d2a47f900637a043f667331cace2ee2d84d886b03ed698f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 14, 2025.
Transparency logRelease files / free_apis_llm_cascade-0.3.2-py3-none-any.whl
| Download URL | free_apis_llm_cascade-0.3.2-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56f8accac10e72c4741bddd4120c963ef7d7e8353fe2a274b1df7f4d72a9f5f7
|
|
BLAKE2b-256 checksum How to use checksums |
a58c697f051dc4b2ae0e0d7fd18d884b3ff65dc3228e78f7aa1f59d1465c425d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 14, 2025.
Transparency logSecurity for free-apis-llm-cascade 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for free_apis_llm_cascade-0.3.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 14, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.