Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gojiplus/gringotts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gringotts: Quick Monetization of Your API

Reduce time to monetize your API.

Solution

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.

Outcome

Users can:

  1. Create an API Key
  2. Delete an API Key. Money is returned to the user account.
  3. Add money to an API Key
  4. Monitor their API credits remaining and the requests they made and how much each cost
  5. Get response from an API if API Key has credits remaining. Otherwise error 'too few credits.'

Quick Example

  1. Start the API:
uvicorn gringotts.main:app
  1. 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)
  1. 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"}'

Development

Install dependencies and run the test suite:

python -m venv venv
source venv/bin/activate
pip install -r gringotts/requirements.txt
pytest -q

CLI Helpers

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

Authors

About

Quick Monetization of Your API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published