How to use an API gateway with the Python OpenAI SDK

Set the SDK's base_url to the OpenAI-compatible gateway and use the gateway key. Add the provider credential to the gateway separately.

Example

A Python worker calls chat.completions.create directly. The integration needs a different client endpoint and credential, plus a small acceptance test.

What to do

  1. Add the upstream key in Spendplane's Providers settings and create a scoped workspace key. Store the workspace key in the worker environment.
  2. Construct the client with base_url set to https://api.spendplane.com/v1 for the shared gateway. Keep the chosen model ID valid for your provider.
  3. Run a synthetic completion and check the configured workspace usage, then test streaming or tool calls if your application needs them.

How to verify

The worker finishes with a provider completion and the gateway reports the correct workspace and model.

Limits

OpenAI-compatible Chat Completions and the Responses API are different request formats. Confirm the endpoint needed by your code.

Spendplane for this workflow

Set up a Spendplane gateway key

Related reading