Practical integration

OpenAI-compatible API: SDK setup

Connect an existing Python client to CLODEx: base URL, key, model and response handling. The guide ends with features that need separate checks when migrating from another API.

What to change in the existing client

Check /v1/models with your key before running the example. A listed ID does not by itself confirm Chat Completions support; match it to the model’s documentation. If your application needs Responses, use its SDK method and response handler rather than changing only the URL.

SettingCLODEX valueReason
base_urlhttps://clodex.xyz/v1The SDK adds the method path. Do not include /chat/completions in base_url.
api_keyCLODEX_API_KEY from the environmentDo not send a CLODEX key to the previous provider.
modelCLODEX_MODEL: exact ID available to your keyDo not assume an alias or model from an old example is available.
timeout / max_retries60 seconds / 0 in this exampleOne diagnostic attempt without hidden automatic retries.

Check your key · Protocol differences

Minimal Python request with the OpenAI SDK

Install the package with python -m pip install openai in your application environment. Set CLODEX_API_KEY and CLODEX_MODEL outside the source file. The example requires a model supporting Chat Completions and sends a paid generation request. Reading this page sends nothing.

The 60-second timeout is a diagnostic setting, not a promised response time. max_retries=0 disables SDK retries. The example omits temperature, tools and other optional fields so the first test covers only the basic contract.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["CLODEX_API_KEY"],
    base_url="https://clodex.xyz/v1",
    timeout=60.0,
    max_retries=0,
)
response = client.chat.completions.create(
    model=os.environ["CLODEX_MODEL"],
    messages=[{"role": "user", "content": "Reply with one word: ready"}],
    stream=False,
)
if not response.choices:
    raise RuntimeError("Missing choices")
choice = response.choices[0]
if choice.finish_reason != "stop" or not choice.message.content.strip():
    raise RuntimeError(f"Unexpected result: {choice.finish_reason}")
print(choice.message.content)
print(response.usage)

Official Python SDK configuration

What makes the check successful?

  • The response has choices, non-empty message.content and a stop finish_reason. The exact word “ready” is not guaranteed; the check validates structure, not string equality.
  • A length finish_reason indicates truncation. tool_calls means the model requested a tool, not that a final user-facing answer is ready.
  • Compare usage with actual spending in the dashboard. Do not publish requests containing secrets or user data in test reports.
  • Test streaming and error handling separately, then add required tools or JSON output capabilities.

Usage reference (Russian) · Rates for your model

What compatibility does not guarantee

Compatibility does not mean every OpenAI feature is implemented. Stored responses, built-in search, file uploads, batch, JSON Schema and reasoning parameters each require confirmation for the route and model you use.

Chat Completions returns choices; Responses uses output items and a response state. An SSE stream is not one ordinary JSON response. Do not present an interrupted connection as a completed answer.

For 400, inspect the error body and submitted fields. For 401, check the key and destination. For 429, identify the stated restriction. After a timeout, do not retry blindly: the previous generation may have completed and incurred usage.

Get help with an error (Russian)

Documentation and example scope

Connection settings follow CLODEx documentation. Examples target the stated protocol; they are not recorded inference results and do not promise identical features across models. A successful generation request can incur a charge.

Client configuration · API protocols

Frequently asked questions

Do I need to rewrite the entire application?

Not necessarily. Settings may be enough if the method and parameters are supported. Still validate parsing, error handling and the capabilities your app depends on.

Can I keep using an OpenAI key?

No. CLODEX requires a CLODEX key and endpoint. Changing only one creates an incorrect configuration.

Is CLODEX an official OpenAI service?

No. It is a separate gateway with compatible routes. Using the OpenAI SDK does not imply a partnership or an identical feature set.

Connect CLODEX API to your application

One key-management layer, compatible endpoints and several LLM families for apps, agents and developer tools.