NESTAIDOCS
NestAI Docs

API REFERENCE

NestAI provides an OpenAI-compatible API to build AI-powered apps on top of your private infrastructure. Same APIs, same SDKs — but your data stays on your server.

Works with OpenAI SDKs, LangChain, LlamaIndex, AutoGen, and any tool that supports OpenAI APIs.

Base URL

Base URL
https://nestai.chirai.dev/api/v1

Authentication

Authorization Header
Authorization: Bearer nai-xxxxxxxx

Generate your API key from Dashboard → API.

Do not use Open WebUI keys. Only NestAI API keys work here.

Core Endpoints

EndpointMethodDescription
/chat/completionsPOSTGenerate responses (OpenAI compatible)
/modelsGETList available models

Basic Usage

cURL
curl https://nestai.chirai.dev/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.1",
    "messages": [
      { "role": "user", "content": "Write a sales email" }
    ]
  }'

What You Can Build

1. Chat Applications

Build ChatGPT-like interfaces using your own models. Perfect for internal tools, support systems, or customer-facing apps.

2. AI Agents

Use with LangChain or AutoGen to build autonomous agents that run privately.

3. Document Q&A (RAG)

Upload documents and query them using the files field.

RAG Example
{
  "model": "llama3.1",
  "messages": [{ "role": "user", "content": "Summarise this doc" }],
  "files": [{ "type": "collection", "id": "YOUR_COLLECTION_ID" }]
}

4. Code Generation

Use coding models like qwen2.5-coder for: - code generation - debugging - refactoring

5. Automation & Workflows

Integrate into backend workflows: - email generation - report summarisation - CRM automation

6. Internal Tools

Build private AI tools for: - legal review - HR queries - financial analysis

Streaming Responses

Python Streaming
from openai import OpenAI

client = OpenAI(
  base_url="https://nestai.chirai.dev/api/v1",
  api_key="YOUR_API_KEY"
)

with client.chat.completions.stream(
  model="llama3.1",
  messages=[{"role": "user", "content": "Explain AI"}],
) as stream:
  for text in stream.text_stream:
    print(text, end="")

SDK Usage

Node.js

import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://nestai.chirai.dev/api/v1",
  apiKey: "YOUR_API_KEY"
})

const res = await client.chat.completions.create({
  model: "llama3.1",
  messages: [{ role: "user", content: "Hello" }]
})

console.log(res.choices[0].message.content)

Python

from openai import OpenAI

client = OpenAI(
  base_url="https://nestai.chirai.dev/api/v1",
  api_key="YOUR_API_KEY"
)

res = client.chat.completions.create(
  model="llama3.1",
  messages=[{"role": "user", "content": "Hello"}]
)

print(res.choices[0].message.content)

Build a Working AI App in 5 Minutes

Spin up a simple AI chat app using NestAI in under 5 minutes. This uses the OpenAI SDK — just replace the base URL.

1. Install dependencies

npm init -y
npm install openai express cors dotenv

2. Create .env file

NESTAI_API_KEY=your_api_key_here

3. Create server (server.js)

import express from "express"
import OpenAI from "openai"
import cors from "cors"
import dotenv from "dotenv"

dotenv.config()

const app = express()
app.use(cors())
app.use(express.json())

const client = new OpenAI({
  baseURL: "https://nestai.chirai.dev/api/v1",
  apiKey: process.env.NESTAI_API_KEY
})

app.post("/chat", async (req, res) => {
  const { message } = req.body

  const response = await client.chat.completions.create({
    model: "llama3.1",
    messages: [{ role: "user", content: message }]
  })

  res.json({
    reply: response.choices[0].message.content
  })
})

app.listen(3000, () => {
  console.log("Server running on http://localhost:3000")
})

4. Run server

node server.js

5. Test it

curl http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Explain AI in simple terms"}'
You now have a working AI backend powered by your private NestAI server.
---

Frontend Example (Optional)

async function sendMessage(message) {
  const res = await fetch("http://localhost:3000/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ message })
  })

  const data = await res.json()
  return data.reply
}

Connect this function to any UI (React, Vue, plain HTML) to build a full chat app.

---

Next Steps

GoalWhat to do
Build chatbot UIConnect frontend to /chat endpoint
Add memoryStore messages in DB
Use RAGAttach knowledge collections
Use better modelsSwitch to Qwen / DeepSeek
Scale usageDeploy backend on your infra
If you’ve used OpenAI before, everything works the same — just replace the base URL.

Models

Call /models to see available models on your server.

Features

FeatureDetails
OpenAI CompatibleWorks with existing SDKs
No Rate LimitsNo RPM/TPM restrictions
Private by DefaultData never leaves your server
StreamingReal-time responses
Multi-modelUse any installed model

Helpful Resources

ResourceLink
OpenAI API Docshttps://platform.openai.com/docs
LangChain Docshttps://docs.langchain.com
LlamaIndex Docshttps://docs.llamaindex.ai
If it works with OpenAI — it works with NestAI.