Node.js SDK

The official Node.js library for rNet OAuth authentication and authenticated AI calls.

NPM: @rnet-ai/rnet-oauth-node

Installation

bash
npm install @rnet-ai/rnet-oauth-node

1. Initialize the Clients

javascript
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)

javascript
const { verifier, challenge } = auth.generatePKCE();
const authUrl = auth.getAuthorizationUrl(challenge, 'optional-state');

3. Exchange Code for Tokens

javascript
const tokens = await auth.exchangeCodeForToken(code, verifier);
const accessToken = tokens.access_token;
const refreshToken = tokens.refresh_token;

4. Refresh Tokens

javascript
const refreshedTokens = await auth.refreshAccessToken(refreshToken);
const newAccessToken = refreshedTokens.access_token;

5. Get User Info

javascript
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

javascript
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)

javascript
const stream = await ai.chatStream(payload, accessToken, "gemini-2.5-flash-lite");
// Process the ReadableStream...

8. File Upload (Untested)

javascript
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)

javascript
// 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)

javascript
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.