Code Examples
Ready-to-use examples for calling Hypervize Inference from various languages and frameworks.
Code Examples
Copy-paste patterns for Elastic (chat, tools, embeddings). For Dedicated, change the URL to /api/d/{endpoint-id}/chat/completions and use the correct auth. Prefer catalog display names (e.g. claude-sonnet-5) for the model field.
cURL (Streaming)
curl -N https://hypervize.tech/api/chat/completions \
-H "Authorization: Bearer $HVZ_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mistral-large-3",
"messages": [{"role": "user", "content": "Explain RAG in 3 bullet points"}],
"max_tokens": 300,
"stream": true
}'Python (OpenAI SDK — Recommended)
from openai import OpenAI
client = OpenAI(
base_url="https://hypervize.tech/api",
api_key="hvz_live_..."
)
stream = client.chat.completions.create(
model="claude-sonnet-5",
messages=[{"role": "user", "content": "Write a haiku about GPUs"}],
max_tokens=150,
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")JavaScript / TypeScript (fetch)
const response = await fetch("https://hypervize.tech/api/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.HVZ_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "llama-3-3-70b-instruct",
messages: [{ role: "user", content: "Hello" }],
stream: true,
}),
});
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader!.read();
if (done) break;
const chunk = decoder.decode(value);
// Parse SSE lines starting with "data: "
console.log(chunk);
}Tool Calling Examples
Plain OpenAI tools (client executes) – cURL
curl -N https://hypervize.tech/api/chat/completions \
-H "Authorization: Bearer $HVZ_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"messages": [{"role":"user","content":"What is the weather in Nashville?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"stream": true
}'Webhook tool (server-managed)
Note: Server-managed tools require
"stream": true.
{
"tools": [{
"type": "function",
"function": { "name": "my_internal_tool", "description": "...", "parameters": {...} },
"webhook": {
"url": "https://myapp.com/api/ai-tools/internal",
"key": "my-secret-key-123",
"timeout_seconds": 25
}
}]
}Hypervize will call your endpoint with a signed payload and drive the loop.
Using Built-in Platform Tools
Platform tools you can enable in Alexandria (or via /api/tools):
| Product | Callable names | Notes |
|---|---|---|
| Athena | athena | Time/date and basic math |
| Vesper | vesper | Web search and page extraction |
| Herald | herald | Email (explicit user permission required); optional attachment_file_id from Ledger |
| Pandora | pandora_* | Google Workspace / Gmail suite |
| Iris | iris | Image generation from text |
| Ledger | ledger | Create/read/convert files (CSV, PDF, JSON, …); Library → Files |
| Chronos | — | Product flag only — enables Chat Schedule and Chronos API jobs; not injected as a model tool |
curl -N https://hypervize.tech/api/chat/completions \
-H "Authorization: Bearer $HVZ_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mistral-large-3",
"messages": [{"role": "user", "content": "What time is it and what is 15 * 7?"}],
"stream": true
}'When Athena (or other platform tools) is enabled for your account, those tools are available on streaming requests. Hypervize executes them server-side and continues the turn.
See the full Platform Tools reference for parameters and pricing.
Vercel AI SDK with custom tools
See the full example in the Tool Calling guide.
LangChain (Python)
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://hypervize.tech/api",
api_key="hvz_live_...",
model="qwen3-32b",
)
response = llm.invoke("Explain why streaming matters for LLMs")
print(response.content)LlamaIndex
LlamaIndex works via the same OpenAI-compatible base URL. Set:
from llama_index.llms.openai import OpenAI
llm = OpenAI(
api_base="https://hypervize.tech/api",
api_key="hvz_live_...",
model="nemotron-3-super-120b",
)Embeddings
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://hypervize.tech/api",
api_key="hvz_live_..."
)
response = client.embeddings.create(
model="cohere.embed-v4",
input="The quick brown fox jumps over the lazy dog."
)
print(response.data[0].embedding[:5]) # first 5 dimensionscURL
curl https://hypervize.tech/api/embeddings \
-H "Authorization: Bearer $HVZ_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "cohere.embed-v4",
"input": "The quick brown fox jumps over the lazy dog."
}'JavaScript / TypeScript
const response = await fetch("https://hypervize.tech/api/embeddings", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.HVZ_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "cohere.embed-v4",
input: "The quick brown fox jumps over the lazy dog.",
}),
});
const data = await response.json();
console.log(data.data[0].embedding.length); // dimension countNotes for Production Clients
- Always set a reasonable
timeout/read_timeout. - Implement retry logic with exponential backoff on 429 / 5xx. Some Elastic models may already try an alternate catalog model under provider rate limits before you see an error; still handle 429/5xx when capacity is exhausted.
- Parse usage from the final chunk for cost tracking.
- Prefer the official OpenAI SDK when possible — it handles SSE edge cases well.
Scheduled tools (Chronos)
To run ordered platform tools and optional model steps on a schedule (API key, full JavaScript client), see Chronos. Chronos is enabled as a product toggle; it is not a model-callable function.
More Examples
Need an example for a specific framework (Vercel AI SDK, AutoGen, CrewAI, etc.)? Let us know — we are expanding this section.