<aside>

Overview

:ambient-logo-original: Docs Home

What is Ambient?

Getting Started

Testnet

App

API

On-Chain

Tool Oracle

Claude Code

Miners

Encyclopedia

Solana Quickstart

Developers

OpenAI SDK

Anthropic SDK

API Docs

API Playground

Links

🌐 Homepage

✉️ [email protected]

:discord-symbol-blurple: Discord

:github-mark-white-bg: github.com/ambient-xyz

:x-logo-black: @ambient_xyz

:x-logo-black: @IridiumEagle

</aside>

This guide shows how to use the Anthropic SDK to connect to Ambient's inference API.

Prerequisites

  1. An Ambient API key from app.ambient.xyz/keys
  2. The Anthropic SDK installed for your language

Python

Installation

pip install anthropic

Usage

import anthropic

client = anthropic.Anthropic(
    base_url="<https://api.ambient.xyz>",
    api_key="your-ambient-api-key",
)

message = client.messages.create(
    model="zai-org/GLM-4.6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, how are you?"}
    ],
)

for block in message.content:
    if block.type == "thinking":
        print("Reasoning:", block.thinking)
    elif block.type == "text":
        print("Response:", block.text)

Streaming

import anthropic

client = anthropic.Anthropic(
    base_url="<https://api.ambient.xyz>",
    api_key="your-ambient-api-key",
)

with client.messages.stream(
    model="zai-org/GLM-4.6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a short poem about coding."}
    ],
) as stream:
    for event in stream:
        if event.type == "content_block_delta":
            if event.delta.type == "thinking_delta":
                print(event.delta.thinking, end="", flush=True)
            elif event.delta.type == "text_delta":
                print(event.delta.text, end="", flush=True)

JavaScript / TypeScript

Installation

npm install @anthropic-ai/sdk

Usage

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

const client = new Anthropic({
  baseURL: "<https://api.ambient.xyz>",
  apiKey: "your-ambient-api-key",
});

const message = await client.messages.create({
  model: "zai-org/GLM-4.6",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "Hello, how are you?" }
  ],
});

for (const block of message.content) {
  if (block.type === "thinking") {
    console.log("Reasoning:", block.thinking);
  } else if (block.type === "text") {
    console.log("Response:", block.text);
  }
}

Streaming

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

const client = new Anthropic({
  baseURL: "<https://api.ambient.xyz>",
  apiKey: "your-ambient-api-key",
});

const stream = client.messages.stream({
  model: "zai-org/GLM-4.6",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "Write a short poem about coding." }
  ],
});

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

Environment Variables

You can also configure the SDK using environment variables:

export ANTHROPIC_BASE_URL=https://api.ambient.xyz
export ANTHROPIC_API_KEY=your-ambient-api-key

Then simply instantiate the client without arguments:

# Python
client = anthropic.Anthropic()

// JavaScript
const client = new Anthropic();

Resources