Coding agents

OpenAI SDK

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

Success — tested

2026-10-10. local text and streaming smoke tests. Versions: Python 3.28.0; TypeScript 7.32.0.

Use the OpenAI SDK to call POST /v1/chat/completions. 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 openai==3.28.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 includes /v1; call chat.completions.create, because the gateway does not expose Responses.

openai-example.py
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["UNUSED_API_KEY"],
    base_url="https://unused.market/v1",
)
raw = client.chat.completions.with_raw_response.create(
    model=os.environ["UNUSED_MODEL"],
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
    max_tokens=64,
)
result = raw.parse()
print(result.choices[0].message.content)
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 openai-example.py
TypeScript
npx tsx openai.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.

openai-stream.py
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["UNUSED_API_KEY"], base_url="https://unused.market/v1")
stream = client.chat.completions.create(
    model=os.environ["UNUSED_MODEL"],
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
    max_tokens=64,
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
    if chunk.usage:
        print("\nusage:", chunk.usage)
print()

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

The Chat Completions surface rejects n other than 1, logprobs, top_logprobs, logit_bias, audio fields, and non-text output modalities. Use a model and offer that support the features you send.

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 3.28.0; TypeScript 7.32.0. Official OpenAI SDK documentation. Local smoke tests cover text and streaming only; they do not validate every provider or coding workflow.

On this page