Open Beta Archipelag.io is in open beta until June 2026. All credits and earnings are virtual. Read the announcement →

Python SDK

pip install and chat in 5 lines

Quickstart: Python SDK

Go from zero to working chat in 5 lines of Python.

### Install the SDK ```bash pip install archipelag ``` ### Send a chat request ```python from archipelag import Client client = Client(api_key="your-api-key-here") result = client.chat("Say hello in three languages") print(result.content) ``` ### Run it ```bash export ARCHIPELAG_API_KEY="your-api-key-here" python hello.py ``` ``` Hello! (English) Bonjour! (French) Hola! (Spanish) ```

Using the response

client.chat() returns a ChatResult with these fields:

result = client.chat("Say hello in three languages")

result.content        # "Hello! (English)\nBonjour!..."
result.job_id         # "550e8400-e29b-41d4-a716-446655440000"
result.finish_reason  # "stop"
result.usage.prompt_tokens       # 12
result.usage.completion_tokens   # 18
result.usage.total_tokens        # 30
result.usage.credits_used        # Decimal("0.001")

Streaming

Use client.chat_stream() to receive tokens as they’re generated:

from archipelag import Client

client = Client(api_key="your-api-key-here")

for event in client.chat_stream("Say hello in three languages"):
    if event.type == "token":
        print(event.content, end="", flush=True)
    elif event.type == "done":
        print()  # newline
        print(f"Tokens used: {event.usage.total_tokens}")

Options

Both methods accept the same options:

result = client.chat(
    "Translate 'hello world' to Japanese",
    system_prompt="You are a helpful translator.",
    max_tokens=256,
    temperature=0.3,
    workload="llm-chat",  # default
)

Environment variable

The client reads ARCHIPELAG_API_KEY automatically if no api_key is passed:

# Uses ARCHIPELAG_API_KEY from environment
client = Client()

Next steps