Anvat

Snippets

Pick your stack. Copy. Ship.

13 verified copy-paste snippets covering the language × framework × model combos people actually ask for. Substitute your Anvat key and the program runs.

Language

Framework

Model

Showing 13 of 13 snippets

Opus 4.8 via Anthropic SDK

Drop-in: same SDK you'd use against Anthropic, one base_url change.

PythonAnthropic SDKClaude Opus 4.8
# pip install anthropic
import anthropic

client = anthropic.Anthropic(
    api_key="sk-anvat-...",            # your Anvat key
    base_url="https://api.anvat.app",  # the one change
)

res = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Explain MoE routing in one paragraph."}],
)
print(res.content[0].text)

Sonnet 4.6 streaming

SSE streaming with the official Anthropic SDK — token-by-token output.

PythonAnthropic SDKClaude Sonnet 4.6streaming
import anthropic

client = anthropic.Anthropic(
    api_key="sk-anvat-...",
    base_url="https://api.anvat.app",
)

with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about Postgres."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

GPT-5 via OpenAI SDK

The OpenAI Python SDK works against Anvat with a base_url override.

PythonOpenAI SDKGPT-5
# pip install openai
from openai import OpenAI

client = OpenAI(
    api_key="sk-anvat-...",
    base_url="https://api.anvat.app/v1",
)

res = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "Two sentences on Rust traits."}],
)
print(res.choices[0].message.content)

Haiku 4.5 via the OpenAI shape

Yes — call Claude through the OpenAI SDK shape. Anvat translates.

PythonOpenAI SDKClaude Haiku 4.5streaming
from openai import OpenAI

client = OpenAI(
    api_key="sk-anvat-...",
    base_url="https://api.anvat.app/v1",
)

stream = client.chat.completions.create(
    model="claude-haiku-4-5",   # any Anvat-catalog model works here
    messages=[{"role": "user", "content": "Quick brainstorm of cache eviction strategies?"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)

Vercel AI SDK + Sonnet 4.6

Edge-friendly streaming with the @ai-sdk/openai provider pointed at Anvat.

TypeScriptVercel AI SDKClaude Sonnet 4.6streaming
// npm i ai @ai-sdk/openai
import { createOpenAI } from "@ai-sdk/openai";
import { streamText } from "ai";

const anvat = createOpenAI({
  baseURL: "https://api.anvat.app/v1",
  apiKey: process.env.ANVAT_API_KEY!,
});

const { textStream } = await streamText({
  model: anvat("claude-sonnet-4-6"),
  prompt: "Outline a 3-step database migration plan.",
});

for await (const part of textStream) {
  process.stdout.write(part);
}

Tool use with Opus 4.8

Define a tool, let Opus decide when to invoke it, and route the call yourself.

TypeScriptAnthropic SDKClaude Opus 4.8
// npm i @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANVAT_API_KEY!,
  baseURL: "https://api.anvat.app",
});

const res = await client.messages.create({
  model: "claude-opus-4-8",
  max_tokens: 1024,
  tools: [
    {
      name: "get_weather",
      description: "Get current weather for a city.",
      input_schema: {
        type: "object",
        properties: { city: { type: "string" } },
        required: ["city"],
      },
    },
  ],
  messages: [{ role: "user", content: "What's the weather in Hanoi?" }],
});

console.log(res.content);

DeepSeek V4 Pro via LangChain

ChatOpenAI with a custom configuration — DeepSeek for cheap reasoning at scale.

TypeScriptLangChainDeepSeek V4 Pro
// npm i langchain @langchain/openai
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "deepseek-v4-pro",
  apiKey: process.env.ANVAT_API_KEY,
  configuration: { baseURL: "https://api.anvat.app/v1" },
});

const res = await llm.invoke("Classify this ticket: 'My credit card was declined twice.'");
console.log(res.content);

Go — raw /v1/messages call

Pure Go stdlib. No SDK dependency. Useful for embedding into existing services.

GoRaw HTTPClaude Sonnet 4.6
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

type message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}
type req struct {
	Model     string    `json:"model"`
	MaxTokens int       `json:"max_tokens"`
	Messages  []message `json:"messages"`
}

func main() {
	body, _ := json.Marshal(req{
		Model:     "claude-sonnet-4-6",
		MaxTokens: 512,
		Messages:  []message{{Role: "user", Content: "Hi"}},
	})
	r, _ := http.NewRequest("POST",
		"https://api.anvat.app/v1/messages", bytes.NewReader(body))
	r.Header.Set("x-api-key", "sk-anvat-...")
	r.Header.Set("anthropic-version", "2023-06-01")
	r.Header.Set("content-type", "application/json")

	resp, _ := http.DefaultClient.Do(r)
	defer resp.Body.Close()
	out, _ := io.ReadAll(resp.Body)
	fmt.Println(string(out))
}

Rust — reqwest + tokio

Async Rust example. Haiku 4.5 for fast classification at the edge.

RustRaw HTTPClaude Haiku 4.5
// cargo add reqwest serde_json tokio --features tokio/full
use reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let body = json!({
        "model": "claude-haiku-4-5",
        "max_tokens": 256,
        "messages": [{ "role": "user", "content": "Hello?" }]
    });
    let res = client
        .post("https://api.anvat.app/v1/messages")
        .header("x-api-key", "sk-anvat-...")
        .header("anthropic-version", "2023-06-01")
        .json(&body)
        .send()
        .await?
        .text()
        .await?;
    println!("{res}");
    Ok(())
}

cURL — Anthropic /v1/messages

The 5-second smoke test. Works in any shell.

cURLRaw HTTPClaude Sonnet 4.6
curl https://api.anvat.app/v1/messages \
  -H "x-api-key: sk-anvat-..." \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "hi"}]
  }'

cURL — OpenAI /v1/chat/completions

Same key, OpenAI shape. Useful for sanity-checking client libraries.

cURLRaw HTTPGPT-5
curl https://api.anvat.app/v1/chat/completions \
  -H "Authorization: Bearer sk-anvat-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "messages": [{"role": "user", "content": "hi"}]
  }'

cURL — SSE streaming

Stream tokens in any shell. Add `stream: true` and read SSE off stdout.

cURLRaw HTTPClaude Opus 4.8streaming
curl -N https://api.anvat.app/v1/messages \
  -H "x-api-key: sk-anvat-..." \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-4-8",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{"role": "user", "content": "Stream a short poem."}]
  }'

LiteLLM — Anvat as upstream

Use Anvat as the upstream provider for a self-hosted LiteLLM gateway.

PythonLiteLLMGemini 3.5 Pro
# pip install litellm
from litellm import completion

res = completion(
    model="openai/gemini-3-5-pro",
    messages=[{"role": "user", "content": "hi"}],
    api_base="https://api.anvat.app/v1",
    api_key="sk-anvat-...",
)
print(res["choices"][0]["message"]["content"])

Don't see your combo?

We're actively expanding. Email hello@anvat.app with the language / framework / model you want and we'll add a verified snippet within a day or two.

Related: full API reference with OpenAPI 3.1 + Postman collection, and the integrations catalog for IDE / agent runner setup.