Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

How to Use the NanoGPT API with Python.

Before you gain knowledge: This is my first post on here and I am trying to leave a good first impression, I would be more than happy to get reviews on this…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
CVE & Threat-Kontext · 7 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Before you gain knowledge: This is my first post on here and I am trying to leave a good first impression, I would be more than happy to get reviews on this and what could be changed or optimised to make good tutorials on here! :)

Happy reading!





How to Use the NanoGPT API with Python



If you've been looking for a private, OpenAI-compatible API that doesn't hoard your prompts for training data, NanoGPT is worth checking out. It speaks the same language as OpenAI's API, meaning most of your existing code works with minimal changes, but your data stays yours.



In this guide, I'll walk you through everything: installation, auth, making basic requests, streaming responses, and handling errors properly. By the end, you'll have a working Python client you can drop into any project.





Why NanoGPT?



Before we write any code, let's talk about why you'd pick this over just hitting OpenAI directly:





  • Privacy-first: Your prompts and completions aren't used for model training


  • OpenAI-compatible: Drop-in replacement for most tools and libraries


  • Model variety: Access to models like MiniMax M2.7 and others without managing infrastructure


  • Simple pricing: Pay-per-token, no enterprise contracts required



If you're building something where user data privacy matters — and honestly, when doesn't it? this is a solid choice. For more context on private AI tools, check out ai-privacy-tools.vercel.app.





Installation



Start by installing the official nanogpt package:




pip install nanogpt






Or, if you prefer working with raw HTTP (no judgment — sometimes you want to see exactly what's going on), you can use requests or httpx instead. The API is standard REST + SSE, so any HTTP client works.



If you want the full OpenAI SDK experience, install the OpenAI package and point it at NanoGPT's base URL:




pip install openai






Both approaches work. I'll show you both below.






Authentication



Grab your API key from nano-gpt.com and set it as an environment variable:




export NANOGPT_API_KEY="your-api-key-here"






Never hardcode your API key in source code. Seriously. I've seen production repos with API keys in them and it's always a bad day.






Basic Chat Completion



Let's start with a simple request using the requests library:




import requests
import json

BASE_URL = "https://nano-gpt.com/api/v1"
API_KEY = os.environ.get("NANOGPT_API_KEY")

headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}

payload = {
"model": "minimax/minimax-m2.7",
"messages": [
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "Write a Python function to flatten a nested list."}
],
"temperature": 0.7,
"max_tokens": 1024
}

response = requests.post(f"{BASE_URL}/chat/completions", headers=headers, json=payload)
data = response.json()

print(data["choices"][0]["message"]["content"])






That's it. If you've worked with OpenAI's API before, this should look completely familiar. Same endpoint structure, same request/response format.






Using the OpenAI SDK



Here's the same thing using the official OpenAI Python SDK pointed at NanoGPT:




from openai import OpenAI
import os

client = OpenAI(
api_key=os.environ.get("NANOGPT_API_KEY"),
base_url="https://nano-gpt.com/api/v1"
)

response = client.chat.completions.create(
model="minimax/minimax-m2.7",
messages=[
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "Write a Python function to flatten a nested list."}
],
temperature=0.7,
max_tokens=1024
)

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






This approach is great because any existing code that uses the OpenAI SDK can be migrated to NanoGPT by just changing two lines the API key and the base URL.






Streaming Responses



For longer responses, streaming makes a huge difference in perceived performance. Here's how to do it:




import requests
import json

BASE_URL = "https://nano-gpt.com/api/v1"
API_KEY = os.environ.get("NANOGPT_API_KEY")

headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Accept": "text/event-stream"
}

payload = {
"model": "minimax/minimax-m2.7",
"messages": [
{"role": "user", "content": "Explain the difference between TCP and UDP."}
],
"stream": True,
"max_tokens": 1024
}

response = requests.post(
f"{BASE_URL}/chat/completions",
headers=headers,
json=payload,
stream=True
)

for line in response.iter_lines():
if line:
line = line.decode("utf-8")
if line.startswith("data: "):
chunk = line[6:]
if chunk.strip() == "[DONE]":
break
data = json.loads(chunk)
delta = data["choices"][0]["delta"]
if "content" in delta:
print(delta["content"], end="", flush=True)

print() # Newline after streaming






The key things here: set "stream": True in the payload, add "Accept": "text/event-stream" to headers, and use requests.post(..., stream=True) so it doesn't buffer the entire response. Then iterate over lines and parse the SSE chunks.



With the OpenAI SDK, streaming is even simpler:




stream = client.chat.completions.create(
model="minimax/minimax-m2.7",
messages=[{"role": "user", "content": "Explain TCP vs UDP."}],
stream=True
)

for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)









Error Handling



Don't skip this part. Here's a practical error handling wrapper you can actually use in production:




import requests
from requests.exceptions import RequestException
import time

class NanoGPTClient:
def __init__(self, api_key, base_url="https://nano-gpt.com/api/v1"):
self.base_url = base_url
self.headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}

def chat(self, messages, model="minimax/minimax-m2.7", max_retries=3, **kwargs):
payload = {
"model": model,
"messages": messages,
"max_tokens": kwargs.get("max_tokens", 1024),
"temperature": kwargs.get("temperature", 0.7)
}

for attempt in range(max_retries):
try:
response = requests.post(
f"{self.base_url}/chat/completions",
headers=self.headers,
json=payload,
timeout=30
)

if response.status_code == 200:
return response.json()["choices"][0]["message"]["content"]

if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 2 ** attempt))
print(f"Rate limited. Retrying in {retry_after}s...")
time.sleep(retry_after)
continue

if response.status_code == 401:
raise ValueError("Invalid API key. Check your NANOGPT_API_KEY.")

response.raise_for_status()

except RequestException as e:
if attempt == max_retries - 1:
raise
print(f"Request failed: {e}. Retrying ({attempt + 1}/{max_retries})...")
time.sleep(2 ** attempt)

raise RuntimeError("Max retries exceeded.")






This handles the common pain points:





  • Rate limiting (429): Respects the Retry-After header with exponential backoff


  • Auth errors (401): Gives you a clear message instead of a cryptic stack trace


  • Network failures: Retries with exponential backoff


  • Timeouts: Configurable via the timeout parameter






Putting It All Together



Here's a complete example that ties everything together — a simple CLI chatbot:




import os
from openai import OpenAI

client = OpenAI(
api_key=os.environ.get("NANOGPT_API_KEY"),
base_url="https://nano-gpt.com/api/v1"
)

def chat():
messages = [{"role": "system", "content": "You are a helpful assistant. Be concise."}]

print("NanoGPT Chat (type 'quit' to exit)\n")

while True:
user_input = input("You: ").strip()
if user_input.lower() in ("quit", "exit"):
break

messages.append({"role": "user", "content": user_input})

stream = client.chat.completions.create(
model="minimax/minimax-m2.7",
messages=messages,
stream=True
)

print("AI: ", end="")
assistant_response = ""
for chunk in stream:
if chunk.choices[0].delta.content:
text = chunk.choices[0].delta.content
print(text, end="", flush=True)
assistant_response += text
print("\n")

messages.append({"role": "assistant", "content": assistant_response})

if __name__ == "__main__":
chat()









Quick Reference
































What Value
Base URL https://nano-gpt.com/api/v1
Auth header Authorization: Bearer YOUR_KEY
Chat endpoint /chat/completions
Default model minimax/minimax-m2.7
Streaming Set "stream": true in payload





Wrapping Up



If you were already using OpenAI's Python SDK, migrating to NanoGPT is genuinely a two-line change. If you're starting fresh, you get a clean API that respects your privacy out of the box.



The real win here is that you're not locked into a single provider. Since NanoGPT is OpenAI-compatible, you can swap between providers without rewriting your application code. That's the kind of flexibility worth building on.



Got questions or hit a snag? Drop a comment below. Happy coding.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Community-Diskussion & Kommentare

🌐 Zum Hauptchat

Starte die Diskussion im Social-Chat Broadcast Stream oder reiche oben über „Information ergänzen“ einen Fachbeitrag ein.

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar & Graph

MITRE ATT&CK Matrix Navigator
1 belegte Technik
T1195TA0011 · Command and Control
Supply Chain Compromise
Mitigation: M1045 Code Signing
Quelle: Kontext-Klassifikation des Artikeltextes · Konfidenz 88%
SBOM/Abhängigkeiten mit Dependency-Check/Trivy inventarisieren, Artefakte per Sigstore (cosign) signieren und verifizieren, Update-Kanäle auf Kompromittierung überwachen.
Command and Control
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
4 Knoten · 3 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War dieser Artikel hilfreich?
0
Jetzt Bewertung abgeben
Detail-Bewertung (optional)
Inhalt & Qualität
Quelle & Glaubwürdigkeit
Aktualität
Security Briefing Kostenlos · 1-Klick-Abmeldung

Intelligence Digest — kostenlos

Täglich die wichtigsten Security-News · jederzeit abbestellbar

Verwandte Story-Cluster & Quellen (Vektor-KI)

2 Cluster
2 Quellen
OpenAI counter-sues Apple over trade secret theft
AppleInsider News vor 18 Min.
1 weitere Quelle
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Use the NanoGPT API with Python.

Thematisch verwandte Begriffe: NanoGPT, with, Python · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Widgets & Themen
Widgets werden geladen…
Nächster Beitrag