Complete, runnable scripts you can adapt in minutes. Every snippet uses model: "auto", so each request is routed to the best-fit model and you pay that model's normal rate — no routing fee.
All three scripts use the official OpenAI SDK pointed at NovaToken, with your key stored in an environment variable. Python 3.8+ works everywhere below.
# install the SDK once pip install openai # put your NovaToken key (starts with sk-) in an environment variable # macOS / Linux: export NOVATOKEN_API_KEY="sk-..." # Windows (PowerShell): setx NOVATOKEN_API_KEY "sk-..."
curl https://api.novatoken.dev/v1/chat/completions -H "Authorization: Bearer $NOVATOKEN_API_KEY" -d '{"model":"auto","messages":[{"role":"user","content":"Hi!"}]}' works too.A terminal chat assistant with memory of the conversation. Replies stream in token-by-token like ChatGPT. Because short chat requests route to the smallest capable model, a full back-and-forth costs fractions of a cent.
# bot.py — pip install openai import os from openai import OpenAI client = OpenAI( api_key=os.environ["NOVATOKEN_API_KEY"], base_url="https://api.novatoken.dev/v1", ) SYSTEM = "You are the support assistant for Acme Widgets. Answer briefly and helpfully." history = [{"role": "system", "content": SYSTEM}] print("Support bot ready. Type 'quit' to exit.\n") while True: user = input("You: ").strip() if not user or user.lower() == "quit": break history.append({"role": "user", "content": user}) print("Bot: ", end="", flush=True) stream = client.chat.completions.create( model="auto", # routed per-request, you pay the picked model's rate messages=history, stream=True, ) reply = "" for chunk in stream: delta = chunk.choices[0].delta.content or "" print(delta, end="", flush=True) reply += delta print("\n") history.append({"role": "assistant", "content": reply})
Run it: python bot.py
Splits a big text file into chunks, summarizes each, then merges the partials into one final summary. Long inputs are automatically routed to the long-context model — no manual model juggling.
# summarize.py — pip install openai import os, sys from openai import OpenAI client = OpenAI( api_key=os.environ["NOVATOKEN_API_KEY"], base_url="https://api.novatoken.dev/v1", ) def summarize(text): r = client.chat.completions.create( model="auto", # long inputs go to the long-context model automatically messages=[ {"role": "system", "content": "Summarize the text in 3 concrete bullet points."}, {"role": "user", "content": text}, ], ) return r.choices[0].message.content def main(): path = sys.argv[1] if len(sys.argv) > 1 else "doc.txt" text = open(path, encoding="utf-8").read() CHUNK = 12000 pieces = [text[i:i+CHUNK] for i in range(0, len(text), CHUNK)] print(f"{len(text):,} chars in {len(pieces)} chunk(s)\n") partials = [summarize(p) for p in pieces] if len(partials) == 1: final = partials[0] else: final = summarize("Merge these summaries into one:\n\n" + "\n---\n".join(partials)) print(final) if __name__ == "__main__": main()
Run it: python summarize.py report.txt
Translates a list of strings with four requests in flight at once — hundreds of lines processed in seconds for well under a cent each. Swap the target language or feed it a CSV; the pattern stays the same.
# translate.py — pip install openai import os from concurrent.futures import ThreadPoolExecutor from openai import OpenAI client = OpenAI( api_key=os.environ["NOVATOKEN_API_KEY"], base_url="https://api.novatoken.dev/v1", ) TEXTS = [ "Shipping takes 3-5 business days.", "We offer a 30-day money-back guarantee.", "Contact support if your key stops working.", ] def translate(text, target="Chinese"): r = client.chat.completions.create( model="auto", messages=[ {"role": "system", "content": f"Translate to {target}. Output only the translation."}, {"role": "user", "content": text}, ], temperature=0.2, ) return r.choices[0].message.content.strip() with ThreadPoolExecutor(max_workers=4) as pool: results = list(pool.map(translate, TEXTS)) for src, dst in zip(TEXTS, results): print(src, "->", dst)
Run it: python translate.py
New here? The Quickstart gets you a key in 60 seconds, and the pricing table lists every model. Grab a key and run the first script in under two minutes.