SDK examples
Noduma serves a subset of OpenAI's chat-completions interface, so the OpenAI SDKs work by changing the base URL to https://app.noduma.dev/v1 and using a Noduma API key. curl and the OpenAI Python SDK were tested against the API; the JavaScript examples send the same requests through the official openai package and have not been run against it yet.
Every example reads the key from NODUMA_API_KEY.
export NODUMA_API_KEY=ndm_k_...# pip install openaiimport osfrom openai import OpenAI
client = OpenAI(base_url="https://app.noduma.dev/v1", api_key=os.environ["NODUMA_API_KEY"])// npm install openaiimport OpenAI from 'openai';
const client = new OpenAI({ baseURL: 'https://app.noduma.dev/v1', apiKey: process.env.NODUMA_API_KEY });List the models
Section titled “List the models”curl https://app.noduma.dev/v1/models -H "Authorization: Bearer $NODUMA_API_KEY"for model in client.models.list(): print(model.id, model.model_extra.get("noduma"))const models = await client.models.list();for (const model of models.data) console.log(model.id, model.noduma);Stream an answer
Section titled “Stream an answer”curl -N https://app.noduma.dev/v1/chat/completions \ -H "Authorization: Bearer $NODUMA_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "qwen2.5-7b-instruct-q4_k_m", "stream": true, "messages": [{"role": "user", "content": "Write a haiku about shared GPUs."}]}'stream = client.chat.completions.create( model="qwen2.5-7b-instruct-q4_k_m", messages=[{"role": "user", "content": "Write a haiku about shared GPUs."}], stream=True,)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) if chunk.usage: print("\ncost:", chunk.usage.model_extra.get("noduma_cost"), "credits")const stream = await client.chat.completions.create({ model: 'qwen2.5-7b-instruct-q4_k_m', messages: [{ role: 'user', content: 'Write a haiku about shared GPUs.' }], stream: true,});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? ''); if (chunk.usage) console.log('\ncost:', chunk.usage.noduma_cost, 'credits');}The last chunk before [DONE] carries usage, with the answer's cost. See Streaming.
Use a tool
Section titled “Use a tool”curl https://app.noduma.dev/v1/chat/completions \ -H "Authorization: Bearer $NODUMA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-coder-30b-a3b-instruct-q4_k_m", "messages": [{"role": "user", "content": "What is the weather in Madrid?"}], "tools": [{"type": "function", "function": { "name": "get_weather", "description": "Current weather of a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]} }}] }'tools = [{"type": "function", "function": { "name": "get_weather", "description": "Current weather of a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},}}]answer = client.chat.completions.create( model="qwen3-coder-30b-a3b-instruct-q4_k_m", messages=[{"role": "user", "content": "What is the weather in Madrid?"}], tools=tools,)for call in answer.choices[0].message.tool_calls or []: print(call.function.name, call.function.arguments)const tools = [{ type: 'function', function: { name: 'get_weather', description: 'Current weather of a city', parameters: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },} }];const answer = await client.chat.completions.create({ model: 'qwen3-coder-30b-a3b-instruct-q4_k_m', messages: [{ role: 'user', content: 'What is the weather in Madrid?' }], tools,});for (const call of answer.choices[0].message.tool_calls ?? []) console.log(call.function.name, call.function.arguments);Your program runs the tool and sends its result back as a tool message. See Tools.
Ask only your own PCs
Section titled “Ask only your own PCs”With the Noduma-Routing: own header only the PCs paired to your account answer, free. See Routing.
curl https://app.noduma.dev/v1/chat/completions \ -H "Authorization: Bearer $NODUMA_API_KEY" \ -H "Content-Type: application/json" \ -H "Noduma-Routing: own" \ -d '{"model": "qwen2.5-7b-instruct-q4_k_m", "messages": [{"role": "user", "content": "Hello"}]}'answer = client.chat.completions.create( model="qwen2.5-7b-instruct-q4_k_m", messages=[{"role": "user", "content": "Hello"}], extra_headers={"Noduma-Routing": "own"},)const answer = await client.chat.completions.create( { model: 'qwen2.5-7b-instruct-q4_k_m', messages: [{ role: 'user', content: 'Hello' }] }, { headers: { 'Noduma-Routing': 'own' } },);Read your balance
Section titled “Read your balance”curl https://app.noduma.dev/v1/account -H "Authorization: Bearer $NODUMA_API_KEY"import json, os, urllib.request
request = urllib.request.Request("https://app.noduma.dev/v1/account", headers={"Authorization": "Bearer " + os.environ["NODUMA_API_KEY"]})print(json.load(urllib.request.urlopen(request))["available"])const res = await fetch('https://app.noduma.dev/v1/account', { headers: { Authorization: `Bearer ${process.env.NODUMA_API_KEY}` },});console.log((await res.json()).available);