<aside>
:ambient-logo-original: Docs Home
🌐 Homepage
: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.
pip install anthropic
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)
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)
npm install @anthropic-ai/sdk
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);
}
}
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);
}
}
}
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();