Overview
An OpenAI-compatible SDK can send requests to different services. The SDK does not decide which company receives the request: your base URL does. Your API key and model ID must belong to that destination.
When a Python integration fails after changing providers, check those three values together before changing your prompt or adding retries.
Keep the destination configuration together
Treat the base URL, key and model ID as one configuration. Avoid changing the hostname while leaving a key from the previous provider in place.
For example, a SmarToken key belongs with SmarToken's endpoint. An official DeepSeek key belongs with DeepSeek's endpoint. Similar request formats do not make credentials interchangeable. SmarToken documents this distinction in its API contract [1].
Use separate environment variable names for separate providers. A generic variable called API_KEY makes it easier to accidentally send the wrong credential after switching environments. Check that the variable is present without printing its value.
Make one bounded Python request
Install the SDK in your project environment:
python -m pip install openaiSet SMTOKEN_API_KEY through your local secret settings. Save the following as check_gateway.py. The request uses a small output limit and disables automatic SDK retries so an initial failure is easier to inspect.
import os
from openai import APIConnectionError, APIStatusError, OpenAI
gateway = OpenAI(
base_url="https://thesmartoken.com/v1",
api_key=os.environ["SMTOKEN_API_KEY"],
timeout=30.0,
max_retries=0,
)
try:
result = gateway.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Return the word ready."}],
max_tokens=16,
extra_body={"thinking": {"type": "disabled"}},
)
print(result.choices[0].message.content)
print(result.usage)
except APIStatusError as problem:
print("HTTP status:", problem.status_code)
print("Inspect the response privately before sharing a redacted report.")
except APIConnectionError:
print("Connection failed. Check networking and request logs before retrying.")The SDK's configuration and exception behavior are described in the official Python SDK repository [4]. The timeout is a client waiting limit, not proof that the provider stopped generating.
Read the error before changing anything
| Symptom | First check |
|---|---|
KeyError for the environment variable | The running process has not received the variable |
| Authentication error | Key issuer, destination, revocation and whitespace |
| Unknown model or invalid parameter | Exact route ID and supported fields |
| A 404 or HTML error page | Hostname, path and reverse proxy configuration |
| Balance or budget error | Wallet and key limits at the destination service |
| Rate limit | Response details and provider retry guidance |
For the OpenAI Python client, base_url is the API root. The SDK adds the operation path. Putting a complete chat-completion URL in that setting can construct the wrong request path. Inspect the resulting URL through redacted diagnostics; never publish authorization headers.
Add complexity only after the first request works
Once a plain text request succeeds, restore streaming, tools and other optional fields individually. That makes it easier to identify the feature responsible for a regression.
A successful greeting does not prove that an agent's multi-turn tool loop works. Test the actual conversation history and output requirements before deploying the integration.
Start with the SmarToken quickstart [5] if you need the current setup. If your existing provider already meets your requirements, the same configuration checks can help you repair that integration without switching services.