Reduce time to monetize your API.
We expand the API spec to add a cost field with price in terms of API credits and a translation for cost per credit. We also add an encrypted config to store your Stripe API Key.
Users can:
- Create an API Key
- Delete an API Key. Money is returned to the user account.
- Add money to an API Key
- Monitor their API credits remaining and the requests they made and how much each cost
- Get response from an API if API Key has credits remaining. Otherwise error 'too few credits.'
- Start the API:
uvicorn gringotts.main:app
- Create a user and API key:
from gringotts import auth, db
db_session = db.SessionLocal()
user, api_key = auth.create_user_with_key(db_session, "alice", credits=5)
print(api_key)
- Call the protected endpoint:
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-d '{"input_string": "hello"}'
Install dependencies and run the test suite:
python -m venv venv
source venv/bin/activate
pip install -r gringotts/requirements.txt
pytest -q
Manage users and credits from the command line:
python -m gringotts.cli create-user alice --credits 5
python -m gringotts.cli add-credits alice 3