Node.js SDK
The official Node.js library for rNet OAuth authentication and authenticated AI calls.
NPM: @rnet-ai/rnet-oauth-node
Installation
npm install @rnet-ai/rnet-oauth-node
1. Initialize the Clients
import { RNetAuth, RNetAi } from '@rnet-ai/rnet-oauth-node';
const auth = new RNetAuth({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
redirectUri: 'your-redirect-uri'
});
const ai = new RNetAi();2. Generate Authorization URL (OAuth2 PKCE)
const { verifier, challenge } = auth.generatePKCE();
const authUrl = auth.getAuthorizationUrl(challenge, 'optional-state');3. Exchange Code for Tokens
const tokens = await auth.exchangeCodeForToken(code, verifier);
const accessToken = tokens.access_token;
const refreshToken = tokens.refresh_token;
4. Refresh Tokens
const refreshedTokens = await auth.refreshAccessToken(refreshToken);
const newAccessToken = refreshedTokens.access_token;
5. Get User Info
const userInfo = await auth.getUserInfo(accessToken);
console.log(userInfo.email);
console.log(userInfo.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.
6. Chat with AI
const response = await ai.chat({
contents: [
{ role: 'user', parts: [{ text: 'Hello!' }] }
]
}, accessToken, 'gemini-2.5-flash-lite');
console.log(response);7. Streaming AI Response (Untested)
const stream = await ai.chatStream(payload, accessToken, "gemini-2.5-flash-lite");
// Process the ReadableStream...
8. File Upload (Untested)
import fs from 'fs';
const fileBuffer = fs.readFileSync('document.pdf');
// Upload to Gemini
const geminiUpload = await ai.geminiFileUpload(accessToken, 'gemini-2.5-flash-lite', fileBuffer, 'application/pdf', 'document.pdf');
console.log(geminiUpload.fileReference); // Use this in chat payload
// Upload to OpenAI
const openaiUpload = await ai.openAIFileUpload(accessToken, 'gpt-4o', fileBuffer, 'application/pdf', 'document.pdf');9. File Deletion (Untested)
// Gemini files auto-delete after 48 hours, so there is no delete method.
// Delete an OpenAI file:
await ai.openAIFileDelete(accessToken, "gpt-4o", openaiUpload.fileReference);
10. AI Chat with File & Tools (Untested)
const 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: geminiUpload.fileReference, mimeType: geminiUpload.mimeType } }
]
}
],
tools: [
{ googleSearch: {} } // Enable Google Search tool
]
};
const response = await ai.chat(payload, accessToken, "gemini-2.5-flash-lite");
console.log(response);Repository
View the Node.js SDK on GitHub.