{"slug": "show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access", "title": "Show HN: Rnet-OAuth-Python – Python lib for user-funded AI API access", "summary": "A developer released Rnet-OAuth-Python, an open-source Python library that integrates RNet OAuth authentication with AI provider services, enabling users to pay for AI model token costs directly through their RNet accounts. The library supports OAuth2 PKCE, token management, user info retrieval, and AI chat with streaming and file upload capabilities for models like Gemini and GPT.", "body_md": "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.\n\n**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.\n\n```\npip install rnet-oauth\npython\nfrom rnet_oauth import RNetAuth, RNetAi\n\nauth = RNetAuth(\n    client_id='client-id',\n    client_secret='client-secret',\n    redirect_uri='redirect-uri'\n)\nai = RNetAi()\n# 1. Generate PKCE\npkce = auth.generate_pkce()\nverifier = pkce['verifier']\nchallenge = pkce['challenge']\n\n# 2. Get Authorization URL\n# challenge: PKCE code challenge (optional)\n# state: An optional string to maintain state between the request and callback (recommended for security)\nauth_url = auth.get_authorization_url(challenge, state='optional-state')\n# 3. Exchange code for tokens\ntokens = auth.exchange_code_for_token(code, verifier)\naccess_token = tokens['access_token']\nuser_info = auth.get_user_info(access_token)\nprint(user_info['email'])\nprint(user_info['name'])\n```\n\nThe UserInfo response comes from RNet's `/userinfo`\n\nendpoint and may include:\n`sub`\n\n, `email`\n\n, `email_verified`\n\n, `name`\n\n, `preferred_username`\n\n, `user_id`\n\n, `role`\n\n, and `status`\n\n.\n\n```\nresponse = ai.chat({\n    \"contents\": [\n        {\n            \"role\": \"user\",\n            \"parts\": [{\"text\": \"Hello!\"}]\n        }\n    ]\n}, access_token, \"gemini-2.5-flash-lite\")\nfor chunk in ai.chat_stream({\n    \"contents\": [\n        {\n            \"role\": \"user\",\n            \"parts\": [{\"text\": \"Hello!\"}]\n        }\n    ]\n}, access_token, \"gemini-2.5-flash-lite\"):\n    print(chunk)\nwith open(\"document.pdf\", \"rb\") as f:\n    file_buffer = f.read()\n\n# Upload to Gemini\ngemini_upload = ai.gemini_file_upload(access_token, \"gemini-2.5-flash-lite\", file_buffer, \"application/pdf\", \"document.pdf\")\nprint(gemini_upload['fileReference']) # Use this in chat payload\n\n# Upload to OpenAI\nopenai_upload = ai.openai_file_upload(access_token, \"gpt-4o\", file_buffer, \"application/pdf\", \"document.pdf\")\n# Gemini files auto-delete after 48 hours, so there is no delete method.\n# Delete an OpenAI file:\nai.openai_file_delete(access_token, \"gpt-4o\", openai_upload['fileReference'])\npayload = {\n    \"contents\": [\n        {\n            \"role\": \"user\",\n            \"parts\": [\n                { \"text\": \"Based on this document, what is my name? Also search the web for the current weather in London.\" },\n                { \"fileData\": { \"fileUri\": gemini_upload['fileReference'], \"mimeType\": gemini_upload['mimeType'] } }\n            ]\n        }\n    ],\n    \"tools\": [\n        { \"googleSearch\": {} } # Enable Google Search tool\n    ]\n}\n\nresponse = ai.chat(payload, access_token, \"gemini-2.5-flash-lite\")\nprint(response)\n```\n\nMIT", "url": "https://wpnews.pro/news/show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access", "canonical_source": "https://github.com/rNetAi/rnet-oauth-python", "published_at": "2026-06-16 11:29:20+00:00", "updated_at": "2026-06-16 11:48:47.021659+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "large-language-models", "generative-ai", "ai-infrastructure"], "entities": ["RNet", "Gemini", "GPT-4o", "OpenAI", "Python"], "alternates": {"html": "https://wpnews.pro/news/show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access", "markdown": "https://wpnews.pro/news/show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access.md", "text": "https://wpnews.pro/news/show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access.txt", "jsonld": "https://wpnews.pro/news/show-hn-rnet-oauth-python-python-lib-for-user-funded-ai-api-access.jsonld"}}