Show HN: Rnet-OAuth-Python – Python lib for user-funded AI API access
Rnet-OAuth-Python is a Python backend library for integrating RNet OAuth and AI Provider services, allowing users to authenticate via RNet and pay for AI model token costs directly using their RNet account. It supports OAuth2 PKCE, token management, user info, AI chat with streaming, and file uploads.
Notifications You must be signed in to change notification settings
Fork 0
Star 1
BranchesTags
Open more actions menu
Folders and files
NameName
Last commit message
Last commit date
Latest commit
History
9 Commits
9 Commits
example_flask
example_flask
rnet_oauth
rnet_oauth
.gitignore
.gitignore
LICENSE
LICENSE
README.md
README.md
pyproject.toml
pyproject.toml
Repository files navigation
A Python backend library for integrating RNet OAuth and AI Provider services. This library allows users to authenticate via RNet and pay for AI model token costs directly using their RNet account.
Features
OAuth2 PKCE Support: Secure authorization code flow with automatic code verifier and challenge generation.
Token Management: Exchange authorization codes for tokens and refresh expired tokens.
UserInfo Endpoint: Fetch the authenticated user's RNet profile with an access token.
AI Integration: Easy methods to chat with AI models using standard or streaming responses.
Installation
pip install rnet-oauth
Quick Start
- Initialize the Clients
from rnet_oauth import RNetAuth, RNetAi
auth = RNetAuth( client_id='client-id', client_secret='client-secret', redirect_uri='redirect-uri' ) ai = RNetAi()
- Generate Authorization URL (OAuth2 PKCE)
1. Generate PKCE
pkce = auth.generate_pkce() verifier = pkce['verifier'] challenge = pkce['challenge']
2. Get Authorization URL
challenge: PKCE code challenge (optional)
state: An optional string to maintain state between the request and callback (recommended for security)
auth_url = auth.get_authorization_url(challenge, state='optional-state')
- Exchange Code for Tokens
3. Exchange code for tokens
tokens = auth.exchange_code_for_token(code, verifier) access_token = tokens['access_token']
- Get User Info
user_info = auth.get_user_info(access_token) print(user_info['email']) print(user_info['name'])
The UserInfo response comes from RNet's /userinfo endpoint and may include: sub, email, email_verified, name, preferred_username, user_id, role, and status.
- Chat with AI
response = ai.chat({ "contents": [ { "role": "user", "parts": [{"text": "Hello!"}] } ] }, access_token, "gemini-2.5-flash-lite")
- Streaming AI Response (Untested)
for chunk in ai.chat_stream({ "contents": [ { "role": "user", "parts": [{"text": "Hello!"}] } ] }, access_token, "gemini-2.5-flash-lite"): print(chunk)
- File Upload (Untested)
with open("document.pdf", "rb") as f: file_buffer = f.read()
Upload to Gemini
gemini_upload = ai.gemini_file_upload(access_token, "gemini-2.5-flash-lite", file_buffer, "application/pdf", "document.pdf") print(gemini_upload['fileReference']) # Use this in chat payload
Upload to OpenAI
openai_upload = ai.openai_file_upload(access_token, "gpt-4o", file_buffer, "application/pdf", "document.pdf")
- File Deletion (Untested)
Gemini files auto-delete after 48 hours, so there is no delete method.
Delete an OpenAI file:
ai.openai_file_delete(access_token, "gpt-4o", openai_upload['fileReference'])
- AI Chat with File & Tools (Untested)
payload = { "contents": [ { "role": "user", "parts": [ { "text": "Based on this document, what is my name? Also search the web for the current weather in London." }, { "fileData": { "fileUri": gemini_upload['fileReference'], "mimeType": gemini_upload['mimeType'] } } ] } ], "tools": [ { "googleSearch": {} } # Enable Google Search tool ] }
response = ai.chat(payload, access_token, "gemini-2.5-flash-lite") print(response)
License
MIT
About
Python library for rNet oauth integration, allowing users to authenticate and pay for AI model token costs using their rNet account.
pypi.org/project/rnet-oauth
Topics
oauth
rnet
Resources
Readme
License
MIT license
Uh oh!
There was an error while loading. Please reload this page.
Activity
Stars
1 star
Watchers
0 watching
Forks
0 forks
Report repository
Contributors
Uh oh!
There was an error while loading. Please reload this page.
Languages
Python 100.0%