AI Access API

Understand the single authenticated route used to proxy AI requests through rNet.

Core Concept

Applications make AI requests by sending prompt and completion payloads to the rNet AI proxy. Each successful request deducts credits from the user's centralized rNet account balance.

Supported AI Models

The following models are currently available on rNet:

  • text-embedding-3-small (OpenAI)
  • gemini-2.5-flash-lite (Google)

For a live list of models and their specific capabilities, visit the Supported Models page.

POST /ai

Submit a non-streaming model request. The SDK wraps this endpoint with RNetAi.chat(body, accessToken, model).

ParameterTypeRequiredDescription
access_tokenstringYesUser access token received from the token flow
modelstringYesSelected rNet model/provider route
bodyobjectYesRequest body shaped for the selected AI provider
Provider-Specific Bodies
rNet does not rewrite your request body into another provider's format. If you select OpenAI, send an OpenAI-compatible body. If you select Gemini, send a Gemini-compatible body. Pass provider-specific fields such as stream, tools, or generationConfig when that provider requires them.

OpenAI Embedding Body

javascript
const response = await ai.chat(
  {
    model: 'text-embedding-3-small',
    input: 'Explain quantum computing'
  },
  req.session.rnet.accessToken,
  'text-embedding-3-small'
);

Gemini-Style Body

javascript
const response = await ai.chat(
  {
    contents: [
      {
        role: 'user',
        parts: [{ text: 'Explain quantum computing' }]
      }
    ]
  },
  req.session.rnet.accessToken,
  'gemini-2.5-flash-lite'
);

POST /ai/stream (Not Tested)

Submit a streaming model request. The SDK wraps this endpoint with RNetAi.chatStream(body, accessToken, model).

javascript
app.post('/api/ai/stream', async (req, res) => {
  const body = {
    contents: req.body.messages.map((message) => ({
      role: message.role === 'assistant' ? 'model' : 'user',
      parts: [{ text: message.content }]
    }))
  };

  const stream = await ai.chatStream(
    body,
    req.session.rnet.accessToken,
    'gemini-2.5-flash-lite'
  );

  res.setHeader('Content-Type', 'text/event-stream');
  const reader = stream.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    res.write(decoder.decode(value, { stream: true }));
  }

  res.end();
});

GitHub Links