Use the OpenAI SDK with ULK Cloud: what to change and what to check
Change three values in your OpenAI client: the API key, the base URL (https://api.ulkcloud.com/v1), and the model ID. Text requests with streaming and function calling work as they are. Parameters ULK Cloud does not support are rejected with an error instead of being ignored.
If your app already calls OpenAI through the official SDK, you do not need a new client library to use ULK Cloud. You change three values and keep the rest of your code. This article covers those three values, then the places where ULK Cloud behaves differently from OpenAI, so you can check them before you switch.
The three values to change
from openai import OpenAI
client = OpenAI(
api_key="YOUR_ULK_CLOUD_API_KEY",
base_url="https://api.ulkcloud.com/v1",
)
response = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
- API key. Create one in the ULK Cloud console. Keys start with
sk-ulk-. - Base URL.
https://api.ulkcloud.com/v1. The JavaScript SDK calls this optionbaseURL. - Model. Pick a model ID from the models page, or list them with
GET /v1/models.
What works as it is
Chat Completions (POST /v1/chat/completions) and the Responses API (POST /v1/responses) are both available, with streaming and function calling.
| Part of the request | What is accepted |
|---|---|
| Messages | Text content |
| Output limit | max_tokens, max_completion_tokens, max_output_tokens |
| Sampling | temperature and top_p. Chat Completions also takes stop, seed, presence_penalty, and frequency_penalty |
| Streaming | stream. Chat Completions also takes stream_options.include_usage |
| Function calling | tools of type function, tool_choice, parallel_tool_calls |
Two things are not accepted: image input (message content is text only) and more than one choice per request (n above 1).
Unsupported parameters are rejected, not ignored
Some OpenAI-compatible APIs accept a parameter they do not support and silently drop it. The request succeeds, and you find out later that the setting never took effect.
ULK Cloud returns a 400 error instead, with the code unsupported_parameter and the name of the parameter. If your code sends response_format or logprobs, for example, the first request tells you so.
The Responses API keeps no history
ULK Cloud does not store conversations. A Responses request that sets previous_response_id, or sets store to true, is rejected. Send the whole conversation in input on every request, and leave store out or set it to false.
Errors come back in the OpenAI format
Error bodies have the same error object as OpenAI's, with message, type, param, and code, so the SDK raises its usual exceptions. These are the codes worth handling:
| Status | Code | When |
|---|---|---|
| 401 | invalid_api_key | The key is missing or not valid |
| 402 | insufficient_balance | Your balance cannot cover the request |
| 402 | monthly_limit_reached | The key has reached its monthly spending limit |
| 429 | rate_limit_exceeded | More than 1,000 requests in a minute with one key |
| 400 | secret_detected | The request contains an API key or a private key |
One difference matters for retry logic. OpenAI reports an exhausted quota as a 429. ULK Cloud uses 402 for an empty balance and keeps 429 for the rate limit, so a 429 always means "wait and retry". The Python SDK has no dedicated exception for 402. Catch APIStatusError and read status_code.
Every response also carries an x-request-id header. Log it, so that a single request can be traced later.
What to plan for in billing
ULK Cloud bills each request from a prepaid balance. Two points affect how you write requests.
- Set
max_tokenswhen you know how long the answer should be. Before a request is sent, the most it could cost is held from your balance. A lower limit means a smaller hold, which leaves more of the balance free for requests running at the same time. - A stream you stop early is billed for what was sent. Closing the connection ends the charge there.
Secrets are stopped before the model
A request that contains something that looks like an API key or a private key is rejected before it reaches the model, and you are not charged. If the match is a false positive, or you mean to send the value, add the header X-ULK-Allow-Secrets: true.
client = OpenAI(
api_key="YOUR_ULK_CLOUD_API_KEY",
base_url="https://api.ulkcloud.com/v1",
default_headers={"X-ULK-Allow-Secrets": "true"},
)