CODE ARSENAL

SNIPPET LIBRARY

11 COPY-PASTE SNIPPETS

CLAUDE TYPESCRIPT

Claude Sonnet 4.6: Extended Thinking Streams 2x Faster

Extended thinking in claude-sonnet-4-6 now streams at 2x the previous throughput. Internal reasoning tokens arrive in real-time via the thinking content block, with no additional latency penalty on the first token.

CLAUDE / TYPESCRIPT
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

async function streamWithThinking(prompt: string) {
  const stream = await client.messages.stream({
    model: "claude-sonnet-4-6",
    max_tokens: 16000,
    thinking: {
      type: "enabled",
      budget_tokens: 10000,
    },
    messages: [{ role: "user", content: prompt }],
  });

  let thinkingText = "";
  let responseText = "";

  for await (const event of stream) {
    if (event.type === "content_block_delta") {
      if (event.delta.type === "thinking_delta") {
        thinkingText += event.delta.thinking;
        process.stdout.write("\x1b[2m"); // dim
        process.stdout.write(event.delta.thinking);
        process.stdout.write("\x1b[0m");
      } else if (event.delta.type === "text_delta") {
        responseText += event.delta.text;
        process.stdout.write(event.delta.text);
      }
    }
  }

  return { thinking: thinkingText, response: responseText };
}

streamWithThinking(
  "Design a database schema for a multi-tenant SaaS app with row-level security."
);
GEMINI PYTHON

Gemini 2.5 Pro: Google Search Grounding Free Up to 1,500 Queries/Day

Google has made grounding with Google Search free for up to 1,500 queries per day on Gemini 2.5 Pro via the Gemini API. Previously this was a paid add-on. Beyond 1,500 queries, standard grounding rates apply.

GEMINI / PYTHON
import google.generativeai as genai
import os

genai.configure(api_key=os.environ["GEMINI_API_KEY"])

model = genai.GenerativeModel(
    model_name="gemini-2.5-pro",
    tools=[{"google_search": {}}],
)

response = model.generate_content(
    "What are the latest updates to Claude's API in 2026?",
    generation_config=genai.GenerationConfig(
        temperature=0.1,
    ),
)

# Print grounded response
print(response.text)

# Access grounding metadata (sources)
if response.candidates[0].grounding_metadata:
    for chunk in response.candidates[0].grounding_metadata.grounding_chunks:
        print(f"Source: {chunk.web.uri}")
        print(f"Title: {chunk.web.title}")
ELEVENLABS PYTHON

ElevenLabs: Instant Voice Cloning From 10 Seconds of Audio

ElevenLabs now supports Instant Voice Cloning from as little as 10 seconds of audio via their API. Upload a clean audio sample, get a voice_id back in under 3 seconds, and immediately use it for text-to-speech generation.

ELEVENLABS / PYTHON
import requests
import os

ELEVEN_API_KEY = os.environ["ELEVEN_API_KEY"]

# Step 1: Clone a voice from a short audio sample
def clone_voice(name: str, audio_path: str) -> str:
    with open(audio_path, "rb") as f:
        response = requests.post(
            "https://api.elevenlabs.io/v1/voices/add",
            headers={"xi-api-key": ELEVEN_API_KEY},
            data={"name": name},
            files={"files": (audio_path, f, "audio/mpeg")},
        )
    response.raise_for_status()
    return response.json()["voice_id"]

# Step 2: Generate speech with the cloned voice
def speak(voice_id: str, text: str, output_path: str):
    response = requests.post(
        f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}",
        headers={
            "xi-api-key": ELEVEN_API_KEY,
            "Content-Type": "application/json",
        },
        json={
            "text": text,
            "model_id": "eleven_multilingual_v2",
            "voice_settings": {"stability": 0.5, "similarity_boost": 0.8},
        },
    )
    response.raise_for_status()
    with open(output_path, "wb") as f:
        f.write(response.content)

voice_id = clone_voice("My Narrator", "sample.mp3")
speak(voice_id, "Welcome to the future of voice AI.", "output.mp3")
CLAUDE TYPESCRIPT

Claude Sonnet 4.6 Released

Anthropic released Claude Sonnet 4.6, the latest in the Claude 4 family, with improved reasoning, faster response times, and better instruction following compared to Sonnet 3.7.

CLAUDE / TYPESCRIPT
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic();

const response = await anthropic.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Your prompt here" }]
});

console.log(response.content[0].text);
CLAUDE TYPESCRIPT

Extended Thinking Now Streams in Real-Time

Extended thinking mode in Claude now streams thinking tokens in real-time. Previously the full thinking block was buffered before delivery.

CLAUDE / TYPESCRIPT
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic();

const stream = await anthropic.messages.stream({
  model: "claude-sonnet-4-6",
  max_tokens: 16000,
  thinking: { type: "enabled", budget_tokens: 10000 },
  messages: [{ role: "user", content: prompt }]
});

for await (const event of stream) {
  if (event.type === "content_block_delta") {
    if (event.delta.type === "thinking_delta") {
      process.stdout.write(event.delta.thinking);
    }
    if (event.delta.type === "text_delta") {
      process.stdout.write(event.delta.text);
    }
  }
}
CLAUDE BASH

Claude Code Is Now Generally Available

Claude Code, Anthropic's agentic coding tool that runs in the terminal, exited beta and is now generally available. It can edit files, run tests, commit code, and navigate large codebases autonomously.

CLAUDE / BASH
# Install
npm install -g @anthropic-ai/claude-code

# Navigate to your project and start
cd your-project
claude

# Give it a task
# > Add rate limiting to the /api/auth/login endpoint using Redis
GEMINI PYTHON

Gemini 2.5 Pro Released with 1M Token Context

Google released Gemini 2.5 Pro with a 1 million token context window, improved multimodal reasoning, and native code execution.

GEMINI / PYTHON
import google.generativeai as genai

genai.configure(api_key=os.environ["GEMINI_API_KEY"])
model = genai.GenerativeModel("gemini-2.5-pro")

# Pass entire codebase — 1M tokens available
with open("entire_codebase.txt") as f:
    code = f.read()

response = model.generate_content(f"Summarize this codebase:\n{code}")
print(response.text)
GEMINI PYTHON

Gemini Grounding with Google Search Free Up to 1,500 Queries/Day

Google made the Search grounding feature free for Gemini API users up to 1,500 queries per day, letting the model cite real-time web sources.

GEMINI / PYTHON
import google.generativeai as genai

genai.configure(api_key=os.environ["GEMINI_API_KEY"])
model = genai.GenerativeModel("gemini-2.5-pro")

response = model.generate_content(
    "What happened in AI this week?",
    tools=[{"google_search_retrieval": {}}]
)
print(response.text)

# Access source citations
for chunk in response.candidates[0].grounding_metadata.grounding_chunks:
    print(f"Source: {chunk.web.uri}")
ELEVENLABS PYTHON

ElevenLabs Instant Voice Cloning from 10 Seconds of Audio

ElevenLabs reduced the minimum audio required for instant voice cloning from 1 minute down to 10 seconds while maintaining the same output quality.

ELEVENLABS / PYTHON
import requests
import os

ELEVEN_API_KEY = os.environ["ELEVEN_API_KEY"]

url = "https://api.elevenlabs.io/v1/voices/add"
headers = {"xi-api-key": ELEVEN_API_KEY}
files = {"files": open("sample.mp3", "rb")}
data = {"name": "MyVoice", "description": "Custom voice"}

response = requests.post(url, headers=headers, files=files, data=data)
voice_id = response.json()["voice_id"]
print(f"Voice cloned: {voice_id}")
OTHER TYPESCRIPT

Vercel AI SDK 4.0 — Unified API Across All Major LLMs

Vercel released AI SDK 4.0 with a unified API that works identically across Claude, GPT-4o, Gemini, Mistral, and Llama. Includes streaming, tool use, and structured output.

OTHER / TYPESCRIPT
import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const { text } = await generateText({
  model: anthropic("claude-sonnet-4-6"),
  prompt: "Explain RAG in one paragraph"
});

console.log(text);

// Swap provider in one line — same API
// import { openai } from "@ai-sdk/openai";
// model: openai("gpt-4o")
CHATGPT JAVASCRIPT

OpenAI Realtime API Supports Text and Audio in Same Session

OpenAI's Realtime API now supports mixing text and audio modalities in the same WebSocket session. Send text, receive audio, or switch modes mid-conversation.

CHATGPT / JAVASCRIPT
const ws = new WebSocket(
  "wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview",
  {
    headers: {
      "Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
      "OpenAI-Beta": "realtime=v1"
    }
  }
);

ws.on("open", () => {
  ws.send(JSON.stringify({
    type: "session.update",
    session: {
      modalities: ["text", "audio"],
      voice: "alloy"
    }
  }));
});

ws.on("message", (data) => {
  const event = JSON.parse(data.toString());
  if (event.type === "response.audio.delta") {
    // Handle audio chunk
  }
  if (event.type === "response.text.delta") {
    process.stdout.write(event.delta);
  }
});