Docs

Quickstart

Python quickstart

The siliconnetwork package: sync and async, streaming, typed with Pydantic, and its only dependencies are httpx and pydantic. Python 3.10 or newer.

1. Install and set the key

setup - zsh
pip install siliconnetwork # not on PyPI yet? install it from the repositorypip install "git+https://github.com/ekempinski/siliconnetwork#subdirectory=sdks/python" export SILICON_API_KEY=sn_live_...

Create the key on the API Keys page. The client reads SILICON_API_KEY, or takes api_key=. The package also installs the silicon command: silicon login signs it in from the browser and saves a key without printing it.

2. One chat completion

chat.py
from siliconnetwork import SiliconNetwork client = SiliconNetwork()  # reads SILICON_API_KEY out = client.chat.completions.create(    model="llama-3.2-3b",    messages=[{"role": "user", "content": "Say hello in one line."}],)print(out.choices[0].message.content)print(out.meta.request_id, out.meta.model, out.meta.node)

meta carries the gateway's headers: the request id (quote it to support), the model that served and the node. Extra keyword arguments go into the body, so Silicon Network fields such as models=["fast"] (fallbacks) pass straight through.

3. Stream the answer

stream.py
from siliconnetwork import SiliconNetwork client = SiliconNetwork() stream = client.chat.completions.stream(    model="llama-3.2-3b",    messages=[{"role": "user", "content": "Write a haiku about silicon."}],)for chunk in stream:    if chunk.choices:        print(chunk.choices[0].delta.content or "", end="", flush=True)print()

The stream also has text() for the joined text and final() for the whole completion. AsyncSiliconNetwork has the same calls with await.

4. List the models

models.py
from siliconnetwork import SiliconNetwork client = SiliconNetwork() for model in client.models.list().data:    print(model.id, model.aliases or [])

The list is what the network is serving now. Any id or alias in it works as model.

5. Handle an error

errors.py
from siliconnetwork import SiliconError, SiliconNetwork client = SiliconNetwork() try:    out = client.chat.completions.create(        model="llama-3.2-3b",        messages=[{"role": "user", "content": "Say hello in one line."}],    )    print(out.choices[0].message.content)except SiliconError as err:    if err.is_out_of_credits:        print("Add balance on the Billing page:", err)    elif err.is_rate_limited:        print(f"Rate limited; retry after {err.retry_after} s")    else:        print(err.status, err.code, err.message, err.request_id)
SiliconError
FieldMeaning
statusThe HTTP status: 401 bad key, 402 out of credits or over a spend cap, 403 not allowed, 429 rate limited, 5xx the gateway or node failed.
codeThe machine code, when the body carried one.
request_idThe gateway's request id; quote it to support.
retry_afterSeconds to wait, when the gateway said so.
is_out_of_credits, is_rate_limited402 and 429.

Non-streaming calls retry 429 and 5xx twice by default, honoring Retry-After; set max_retries on the client to change that. Next: Streaming, Structured outputs and tools, Errors.

Silicon Network›Docs›Guides›Quickstarts by language›Python54 items