OpenAI SDK
Use the OpenAI Python and TypeScript SDKs with Boundless: install, base URL, a first request, streaming and a tool call.
The OpenAI SDKs work against Boundless with two changes: the base URL and the key. Everything else is the code you already have.
Install#
Base URL and key#
Set the base URL to https://api.inference.boundless.network/v1. Send a Boundless key where the OpenAI key goes. Create a key, then export it:
Use a model ID exactly as the models table lists it.
Make a request#
Stream the reply#
Set stream to true. Set stream_options.include_usage to true to get exact token counts in the last chunk. That chunk has an empty choices array.
Streaming explains the chunk format.
Call a tool#
Pass your functions in tools. The model answers with the call it wants. This example forces the call and prints it. Tool calling shows the full loop, with streamed arguments and the result sent back.
Known differences#
- Credits that run out return
402withbudget_exceeded. The SDK does not retry a402. A rate-limit429is retried by default, which is what you want. See Errors. - Not every model supports tools.
GET /v1/model/infolists the capability flags. - A reasoning model spends
max_tokenson thinking too. See Reasoning. - The gateway does not serve
/v1/embeddings,/v1/completions,/v1/batches, images or audio. See API Compatibility. POST /v1/responsesserves only the subset Codex CLI uses. Use chat completions from the SDK.- After a
502, a timeout or a dropped stream, checkGET /v1/requests/{id}before you resend. See Retrying safely.