EN ▾
Create key

NoRestricted AI API: Use It in Your App

The norestricted ai api plugs into an app the way any OpenAI-compatible service does: one base URL, one key, one model ID. This article shows how to wire it in cleanly, from environment variables to streaming and tool calls.

Isometric app window plugged into a cloud connector with configuration cards around it

Configuration first

Before any code, decide where settings live. The norestricted ai api needs three values, and none of them belong in source control:

# .env
LLM_BASE_URL=https://api.norestrictedai.com/v1
LLM_API_KEY=your-key-here
LLM_MODEL=uncensored

Using generic names such as LLM_BASE_URL pays off later. If you ever point the same code at another OpenAI-compatible server, for example a local test stub, you change a file, not the app. Add .env to .gitignore and give each environment its own key. Accounts that have topped up can hold up to 5 keys with labels, so create one for development and one for production on the API key page. If a key leaks, regenerate it there and the old one stops working at once.

New accounts can claim $0.50 of trial credit with one click, with no card. That is enough to build the whole integration below.

A deployment checklist for config

  1. Separate keys for development, staging and production, each labeled.
  2. Keys stored in your platform's secret manager, never in the image or repository.
  3. Base URL and model read from the environment, with sane defaults.
  4. A request timeout and a cap on concurrent calls (8 for a full key).
  5. Logging of X-Request-Id, token usage and the balance header.
  6. An alert when the balance drops below a few days of spend.

A shared client in Node

Create the client once and import it everywhere. Constructing a new client per request wastes connections.

// llm.js
import OpenAI from "openai";

export const llm = new OpenAI({
  baseURL: process.env.LLM_BASE_URL ?? "https://api.norestrictedai.com/v1",
  apiKey: process.env.LLM_API_KEY,
  maxRetries: 2,
  timeout: 120_000,
});

export const MODEL = process.env.LLM_MODEL ?? "uncensored";

The SDK's built-in retry handles transient failures. The generous timeout matters because a long completion can take a while. Streaming requests keep a connection open for the full generation.

The equivalent in Python:

# llm.py
import os
from openai import OpenAI

llm = OpenAI(
    base_url=os.environ.get("LLM_BASE_URL", "https://api.norestrictedai.com/v1"),
    api_key=os.environ["LLM_API_KEY"],
    max_retries=2,
    timeout=120,
)
MODEL = os.environ.get("LLM_MODEL", "uncensored")

If your app has both a web server and background workers, give each process its own client but share the concurrency budget. Eight concurrent requests is the cap per key, so split it, for example 5 for interactive traffic and 3 for batch jobs, so a long background run cannot starve live users.

Stream through your own route

Your frontend must never hold the key. Add a server route that calls the API and forwards the text. This Express handler streams server-sent events to the browser:

import express from "express";
import { llm, MODEL } from "./llm.js";

const app = express();
app.use(express.json({ limit: "1mb" }));

app.post("/api/chat", async (req, res) => {
  const { messages } = req.body;
  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Cache-Control", "no-cache");

  const stream = await llm.chat.completions.create({
    model: MODEL,
    messages: [{ role: "system", content: "You are the in-app assistant." }, ...messages],
    stream: true,
  });

  req.on("close", () => stream.controller.abort());

  for await (const chunk of stream) {
    const text = chunk.choices[0]?.delta?.content;
    if (text) res.write(`data: ${JSON.stringify(text)}

`);
  }
  res.write("data: [DONE]

");
  res.end();
});

app.listen(3000);

The close handler matters. A streamed request holds a concurrency slot until the stream ends, and a full key has 8 of them. If users close tabs and you keep generating, slots stay busy and the next requests get 429 with the code concurrency. Aborting frees the slot sooner.

Tool calling for app actions

If the assistant should do things in your app, such as look up an order or fetch a note, use tool calling. The fields are the standard ones: tools, tool_choice, and results returned as role: "tool" messages.

import json
from llm import llm, MODEL

tools = [{
    "type": "function",
    "function": {
        "name": "get_note",
        "description": "Fetch a saved note by id",
        "parameters": {
            "type": "object",
            "properties": {"note_id": {"type": "string"}},
            "required": ["note_id"],
        },
    },
}]

messages = [{"role": "user", "content": "Summarize note 42."}]
first = llm.chat.completions.create(model=MODEL, messages=messages, tools=tools)
msg = first.choices[0].message

if msg.tool_calls:
    messages.append(msg)
    for call in msg.tool_calls:
        args = json.loads(call.function.arguments)
        result = {"note_id": args["note_id"], "text": "Draft chapter outline..."}
        messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
    final = llm.chat.completions.create(model=MODEL, messages=messages, tools=tools)
    print(final.choices[0].message.content)

Always parse arguments defensively and validate them against your own schema before acting. The model suggests a call; your code decides whether to run it. For machine-readable output without tools, set response_format to {"type":"json_object"}.

Respect the limits in production

A full key allows 8 concurrent requests and 300 per minute, with a maximum body of 8 MB. Two patterns keep a busy app inside them.

  • Queue on your side. A small in-process queue or semaphore capped at 8 turns spikes into short waits instead of errors.
  • Back off on 429. The codes are rate_limited and concurrency. If a Retry-After: 5 header is present, wait that long.

Log the X-Request-Id header with every call. It is the first thing to include if you need help with a request. The X-Balance-USD header lets you warn yourself before credit runs out, and the production checklist has the rest of the pre-launch list.

Test without spending

Run your automated tests against a stub, not the live service. A tiny local server that returns a canned chat completion lets your CI run fast and free, and the environment variables above make the swap a one-line change: point LLM_BASE_URL at the stub. Keep a handful of live smoke tests for staging, run on demand, using a labeled staging key and small max_tokens values.

For live tests, remember the trial key allows 2 concurrent requests and 60 per minute, so keep test runners from firing in parallel.

Surface errors to users sensibly

Users should never see a raw stack trace or a bare 429. Map failures to plain messages. For rate_limited and concurrency, show a short wait indicator and retry. For an authentication error, alert yourself, since it means your key was revoked or mistyped, and show the user a generic failure message. For an empty reply, retry once, then fall back to a polite error.

Streaming adds one more case: the connection can drop mid-reply. Decide in advance whether to keep the partial text with a retry button or discard it. Either is fine, as long as the UI does not freeze.

Keep the bill predictable

Billing is prepaid at $0.15 per 1M input tokens and $0.50 per 1M output tokens, and failed or refused requests are not charged. An in-app assistant that sends 1,200 input tokens and receives 300 output tokens costs 1,200 x $0.15 / 1M + 300 x $0.50 / 1M = $0.00018 + $0.00015 = $0.00033 per call.

To keep totals low, cap max_tokens for short-answer features, trim history, and avoid resending large documents on every turn. Context goes up to 100,000 tokens, but you pay for each input token each time. Per-token examples are on the pricing page, and the docs list every parameter. The model is text only, it is not any vendor's official API, and prompts are not used for training.

Add a guard in code so a bug cannot run up the bill: a per-user daily message limit, a global ceiling on calls per minute below the 300 allowed, and a check of the balance header that disables optional features when credit is low. These are a dozen lines each and they turn an incident into a log entry.

Common questions

Can I use the OpenAI SDK in my existing app?

Yes. Change the base URL to https://api.norestrictedai.com/v1, use your key and set the model to uncensored.

Is it safe to call the API from the browser?

No. Anyone could read the key from the page. Call it from your server and expose your own route to the frontend.

Does tool calling work with streaming?

Yes. Tool calls can be streamed, and you return results as messages with the role tool.

How do I replace a leaked key?

Regenerate it on the API key page. The old key stops working at once and no support request is needed.

Access your key instantly

Register, copy the token, point your client to the new base URL. Done.

Summary

  1. Keep base URL, key and model in environment variables so staging and production differ only by config.
  2. Create one shared client per process and never expose the key to the browser.
  3. Stream through your own route and respect the 8-concurrent cap.
  4. Tool calling and JSON mode use the standard OpenAI fields.

Start with trial credits

Enter email and password. Receive key immediately on screen.