Edge & Devices

Get started

CognitivessAI speaks plain HTTP + JSON over the OpenAI-compatible API, so it runs on anything that can make a TLS request — from a Raspberry Pi to a 32 KB microcontroller. All you need is your ssh-ed25519 ... API key and model Cognitivess-1.

EndpointPOST https://api.cognitivess.com/v1/chat/completions
AuthAuthorization: Bearer <API_KEY>
ModelCognitivess-1
TransportHTTPS / TLS 1.2+

On constrained devices, keep max_tokens small (64–512). Shorter responses mean lower latency, fewer tokens billed, and less battery/RAM used. Don't send the default large max_tokens from a microcontroller.

Quick check (any device with a shell)

curl https://api.cognitivess.com/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Cognitivess-1",
    "messages": [{"role":"user","content":"ping"}],
    "max_tokens": 16
  }'

If you get JSON back with choices[0].message.content, your device can talk to CognitivessAI — everything below is just transport code.

Choose your device

# Pi 3/4/5 & Zero 2 W — full Linux, use the OpenAI SDK directly
# sudo apt install -y python3-venv && pip install openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["COG_KEY"],            # cheia ssh-ed25519 din dashboard
    base_url="https://api.cognitivess.com/v1",
)

resp = client.chat.completions.create(
    model="Cognitivess-1",
    messages=[
        {"role": "system", "content": "You are a concise assistant for a Raspberry Pi."},
        {"role": "user", "content": "Sensors: temp=22.4C, humidity=51%. Anything abnormal? One line."},
    ],
    max_tokens=96,
    temperature=0.3,
)
print(resp.choices[0].message.content)
// ESP32 — WiFi + HTTPClient over TLS. No SDK needed, just a JSON POST.
// Install ArduinoJSON to parse the response.
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

const char* WIFI_SSID = "RETEA";
const char* WIFI_PASS = "parola";
const char* API_KEY   = "ssh-ed25519 AAAA...";   // din dashboard
const char* URL       = "https://api.cognitivess.com/v1/chat/completions";

void ask(const String& q) {
  WiFiClientSecure tls;
  tls.setInsecure();              // prod: load root CA with setCACert()
  HTTPClient https;
  https.begin(tls, URL);
  https.addHeader("Content-Type", "application/json");
  https.addHeader("Authorization", String("Bearer ") + API_KEY);
  String body = "{\"model\":\"Cognitivess-1\",\"messages\":[{\"role\":\"user\",\"content\":\""
                + q + "\"}],\"max_tokens\":128,\"temperature\":0.3}";
  int code = https.POST(body);
  if (code > 0) Serial.println(https.getString());   // parse choices[0].message.content
  else   Serial.printf("err: %s\n", https.errorToString(code).c_str());
  https.end();
}
# Raspberry Pi Pico W — MicroPython + urequests. Keep secrets.py out of git.
import network, urequests, ujson, time
from secrets import WIFI_SSID, WIFI_PASS, COG_KEY

URL = "https://api.cognitivess.com/v1/chat/completions"

def connect():
    wlan = network.WLAN(network.STA_IF); wlan.active(True)
    wlan.connect(WIFI_SSID, WIFI_PASS)
    while not wlan.isconnected(): time.sleep(0.5)

def ask(question):
    body = ujson.dumps({"model": "Cognitivess-1",
        "messages": [{"role": "user", "content": question}],
        "max_tokens": 128, "temperature": 0.3})
    r = urequests.post(URL, data=body, headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer " + COG_KEY})
    out = r.json()["choices"][0]["message"]["content"]
    r.close()
    return out

connect()
print(ask("Pico sensor: 23.5C, 48% U. Status?"))
# ESP8266 has little RAM and weak TLS. Run a tiny proxy on a Pi on your LAN
# so the ESP8266 speaks plain HTTP to the Pi, which holds the key & does TLS.
# --- proxy.py on the Pi (pip install fastapi httpx uvicorn) ---
import os, httpx
from fastapi import FastAPI, Request
app = FastAPI()
KEY = os.environ["COG_KEY"]
UP  = "https://api.cognitivess.com/v1"

@app.post("/v1/{path:path}")
async def proxy(path: str, req: Request):
    body = await req.body()
    async with httpx.AsyncClient(timeout=60) as c:
        r = await c.post(f"{UP}/{path}", content=body,
                headers={"Authorization": f"Bearer {KEY}",
                         "Content-Type": "application/json"})
        return r.json()

# ESP8266 now just does: POST http://pi.local:8000/v1/chat/completions  (no key, no TLS)

Voice assistant on Raspberry Pi

Run speech-to-text locally (e.g. whisper --model tiny) and a light TTS (espeak / piper); CognitivessAI handles only the dialog.

from openai import OpenAI
client = OpenAI(api_key=COG_KEY, base_url="https://api.cognitivess.com/v1")

answer = client.chat.completions.create(
    model="Cognitivess-1",
    messages=[
        {"role": "system", "content": "Ești un asistent vocal scurt. Răspunde în română, maxim 2 propoziții."},
        {"role": "user", "content": user_text},   # din whisper STT
    ],
    max_tokens=96, temperature=0.4,
).choices[0].message.content

# subprocess.run(["espeak", "-v", "ro", answer])

Auto-start at boot with a systemd unit (After=network-online.target, Restart=on-failure, key via EnvironmentFile=) so the assistant comes back after power loss.

Home Assistant / MQTT bridge

Expose Cognitivess-1 as an entity in Home Assistant: a small bridge on a Pi subscribes to cognitivess/ask and publishes the answer on cognitivess/answer.

import os, paho.mqtt.client as mqtt
from openai import OpenAI
client = OpenAI(api_key=os.environ["COG_KEY"], base_url="https://api.cognitivess.com/v1")

def on_message(c, u, msg):
    ans = client.chat.completions.create(
        model="Cognitivess-1",
        messages=[{"role": "user", "content": msg.payload.decode()}],
        max_tokens=128, temperature=0.3,
    ).choices[0].message.content
    c.publish("cognitivess/answer", ans)

m = mqtt.Client(); m.on_message = on_message
m.connect("mqtt.local", 1883); m.subscribe("cognitivess/ask")
m.loop_forever()

Industrial gateway (Modbus → Cognitivess-1)

On an edge gateway (Pi, RevPi, OnLogic), read PLC registers over Modbus TCP, then ask Cognitivess-1 for a short diagnosis on a schedule (cron).

from pymodbus.client import ModbusTcpClient
from openai import OpenAI
client = OpenAI(api_key=COG_KEY, base_url="https://api.cognitivess.com/v1")

regs = ModbusTcpClient("192.168.1.10").read_holding_registers(0, 8).registers
summary = ",".join(str(x) for x in regs)
out = client.chat.completions.create(
    model="Cognitivess-1",
    messages=[{"role": "user", "content": f"PLC registers: {summary}. Detect anomaly, propose action. Very short."}],
    max_tokens=160, temperature=0.2,
).choices[0].message.content

Best practices for edge

  • Small max_tokens (64–512): lower latency, cost, and battery use.
  • Retry with backoff (2s → 5s → 15s): edge networks drop often; don't hammer at 1s (rate-limit + battery).
  • Offline fallback: cache the last good answer; if the API is down, show that. Keep simple commands (on/off) on local rules — never gate them behind an LLM.
  • Secrets: never hardcode COG_KEY in firmware. On Pi use env vars / EnvironmentFile; on an MCU use the §ESP8266 proxy so the key stays on the Pi, not in device flash.
  • TLS: validate the cert (setCACert) in production — avoid setInsecure().
  • Streaming ("stream": true): great on a Pi (answers feel instant); skip on ESP8266/Pico (tiny buffers, SSE parsing is painful).
  • Cost: batch sensor data into one summary request instead of one call per reading.
  • Temperature: 0.2–0.4 for deterministic tasks (diagnostics, classification); 0.7+ for creative dialog.
See it in action
A full worked example — an electricity provider reading power-meter indexes automatically with Cognitivess-1 (validation, fraud/anomaly detection, customer messaging).
Use Cases →