Coding agents

Anthropic SDK

Anthropic clients in Python and TypeScript, with request IDs and streaming.

Success — tested

2026-10-10. local text and streaming smoke tests. Versions: Python 1.13.0; TypeScript 0.133.0.

Use the Anthropic SDK to call POST /v1/messages. The SDK selects a wire format; the model ID selects the model you request through the gateway.

Before you start

Complete the Quickstart. Use a funded account, a gateway key, and a model ID copied from Marketplace. Install Python or Node.js, then install the SDK in your project.

Install
python -m pip install anthropic==1.13.0

Set your key and replace the sample model with your chosen ID. Keep the key out of source files.

macOS / Linux
export UNUSED_API_KEY='sk-unused-...'
export UNUSED_MODEL='claude-sonnet-5-5'

Send a request

Save the selected example in your project. The base URL is the host, without /v1; the SDK appends /v1/messages.

anthropic-example.py
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["UNUSED_API_KEY"],
    base_url="https://unused.market",
)
raw = client.messages.with_raw_response.create(
    model=os.environ["UNUSED_MODEL"],
    max_tokens=64,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
result = raw.parse()
for block in result.content:
    if block.type == "text":
        print(block.text)
print("x-request-id:", raw.headers.get("x-request-id"))
print("x-unused-listing:", raw.headers.get("x-unused-listing"))

Run it from the same terminal where you set the variables.

Python
python anthropic-example.py
TypeScript
npx tsx anthropic.mts

You should see the generated text, an x-request-id, and the selected offer's x-unused-listing. Open Analytics → Requests and find the new row by time and model. Keep the request ID when reporting a problem.

Stream a response

Save and run the streaming file with the same Python or TypeScript command, using its filename.

anthropic-stream.py
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ["UNUSED_API_KEY"], base_url="https://unused.market")
with client.messages.stream(
    model=os.environ["UNUSED_MODEL"],
    max_tokens=64,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    print("\nusage:", stream.get_final_message().usage)

A stream can finish with an error after text has arrived. Handle that failure in your application; the gateway does not move an already-started stream to another offer.

Limits and troubleshooting

Set max_tokens on each Messages request. Tools, images, thinking, and cache controls still depend on the selected model and offer.

SymptomCheck
Authentication errorUse the unused.market key in UNUSED_API_KEY.
Route not foundCheck the base URL shape above.
No usable offerCheck Marketplace, Routing, and the key's allowed models.
Credit or key budget errorCheck Credits and the key's monthly limit; reduce the requested output budget if needed.

Sources and verification

Checked on 2026-10-10: Python 1.13.0; TypeScript 0.133.0. Official Anthropic SDK documentation. Local smoke tests cover text and streaming only; they do not validate every provider or coding workflow.

On this page