Replace YOUR_API_KEY with a key from API keys and alice/llama-3.1-8b
with a model id from your account. Model ids are owner/slug.
Chat completion
curl https://api.noket.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "alice/llama-3.1-8b",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Why is the sky blue?"}
],
"temperature": 0.2
}'OpenAI Python
from openai import OpenAI
client = OpenAI(
base_url="https://api.noket.dev/v1",
api_key="YOUR_API_KEY",
)
response = client.chat.completions.create(
model="alice/llama-3.1-8b",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.choices[0].message.content)
print(response.usage)OpenAI Node
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.noket.dev/v1",
apiKey: "YOUR_API_KEY",
});
const response = await client.chat.completions.create({
model: "alice/llama-3.1-8b",
messages: [{ role: "user", content: "Why is the sky blue?" }],
});
console.log(response.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="alice/llama-3.1-8b",
messages=[{"role": "user", "content": "Count to five."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)The usage chunk arrives last and has no choices, so guard the access as above. The same event stream
works with curl -N:
curl -N https://api.noket.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "alice/llama-3.1-8b",
"messages": [{"role": "user", "content": "Count to five."}],
"stream": true
}'Anthropic Python
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.noket.dev/anthropic",
api_key="YOUR_API_KEY",
)
message = client.messages.create(
model="alice/llama-3.1-8b",
max_tokens=512,
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(message.content[0].text)Streaming uses the SDK’s helper, which handles the event types for you:
with client.messages.stream(
model="alice/llama-3.1-8b",
max_tokens=512,
messages=[{"role": "user", "content": "Count to five."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)List the models you can call
curl https://api.noket.dev/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"for model in client.models.list():
print(model.id)from anthropic import Anthropic
anthropic = Anthropic(
base_url="https://api.noket.dev/anthropic",
api_key="YOUR_API_KEY",
)
for model in anthropic.models.list():
print(model.id, model.display_name)Count tokens
count = anthropic.messages.count_tokens(
model="alice/llama-3.1-8b",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(count.input_tokens)Token counting is free and does not touch a budget.
Point an existing application at Noket
Most clients need three changes:
- The base URL —
https://api.noket.dev/v1for OpenAI-shaped clients, orhttps://api.noket.dev/anthropicfor Anthropic-shaped ones. - The key — a Noket API key in place of the provider key.
- The model id — the public
owner/slugid instead of a provider model name.
Both official SDKs read the base URL and key from their constructor or from the environment variables they already support. Supply the key from your process’s secret manager rather than a committed file, and keep the placeholder out of shell history when you try a call by hand. See Authentication for key handling.