Use the OpenAI SDK with CaMeL Hub: One Key for GPT, Claude, Gemini & DeepSeek

The OpenAI SDK (`openai` on PyPI and npm) is the official client library OpenAI publishes for Python, Node.js/TypeScript, and several other languages. It wraps HTTP calls to the Chat Completions and Responses APIs in typed, ergonomic methods β€” `client.chat.completions.create(...)` instead of hand-built `requests.post()` calls. Because it only needs two settings changed, `base_url` and `api_key`, it's also the fastest way to reach CaMeL Hub: point it at our endpoint and the exact same code that talks to OpenAI's models can call Claude, Gemini, DeepSeek, Grok and 480+ other models through one account, one key, and one bill.

OpenAI SDK β†—

  1. Create a CaMeL Hub API key

    Sign in to the CaMeL Hub console at https://api.camel-hub.com/console and open the field named API Keys / Tokens (Console β†’ Token). Click New Token, name it something you'll recognize later (e.g. "openai-sdk-test"), and copy the key right away β€” like an OpenAI key, it's shown once and should be treated as a secret, never committed to source control.
  2. Install the OpenAI SDK

    Install whichever language binding you use. Any current 1.x release works unmodified β€” CaMeL Hub speaks the exact request/response shape the SDK expects, so there's no compatibility shim or fork to install.
    pip install --upgrade openai
    
    # Node.js / TypeScript instead:
    # npm install openai@latest
  3. Point the client at CaMeL Hub

    Create the client with two overrides: `base_url` set to CaMeL Hub's endpoint and `api_key` set to the token from step 1. The SDK appends resource paths such as `/chat/completions` to whatever you pass as `base_url`, so it must already include the `/v1` segment β€” use `https://api.camel-hub.com/v1` exactly, not the bare `https://api.camel-hub.com` host.
    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://api.camel-hub.com/v1",
        api_key="<YOUR_CAMEL_HUB_KEY>",
    )
  4. Send your first request

    Call `chat.completions.create` exactly as you would against OpenAI's own API. Pick any model name from the model marketplace β€” start with a general-purpose one like `gpt-5.5`.
    completion = client.chat.completions.create(
        model="gpt-5.5",
        messages=[
            {"role": "user", "content": "Explain what CaMeL Hub does in one sentence."}
        ],
    )
    
    print(completion.choices[0].message.content)
  5. Call GPT, Claude, Gemini or DeepSeek with the exact same code

    This is the core benefit of routing the OpenAI SDK through CaMeL Hub: the request format never changes, only the `model` string does. CaMeL Hub translates each call into the target provider's native protocol server-side, so a single client instance can round-robin across vendors.
    for model in ["gpt-5.5", "claude-sonnet-5", "gemini-3.1-pro", "deepseek-v4-flash"]:
        resp = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": "Say hello in five words."}],
        )
        print(model, "->", resp.choices[0].message.content)
  6. Stream tokens as they arrive

    Set `stream=True` for incremental output β€” useful for chat UIs or long completions where you don't want to wait for the full response before showing anything.
    stream = client.chat.completions.create(
        model="gpt-5.5",
        messages=[{"role": "user", "content": "Write a haiku about API gateways."}],
        stream=True,
    )
    for chunk in stream:
        delta = chunk.choices[0].delta.content
        if delta:
            print(delta, end="", flush=True)
  7. Same pattern in Node.js / TypeScript

    The JavaScript/TypeScript SDK mirrors the Python one field for field. Read the key from an environment variable rather than hardcoding it in the repo.
    import OpenAI from "openai";
    
    const client = new OpenAI({
      baseURL: "https://api.camel-hub.com/v1",
      apiKey: process.env.CAMEL_HUB_API_KEY,
    });
    
    const completion = await client.chat.completions.create({
      model: "gpt-5.5",
      messages: [
        { role: "user", content: "Explain what CaMeL Hub does in one sentence." },
      ],
    });
    
    console.log(completion.choices[0].message.content);
  8. Sanity-check with curl if something goes wrong

    If the SDK raises a connection or authentication error, hit the endpoint directly to tell apart a key problem from a client-setup problem. A working curl call with a failing SDK call almost always means an environment variable or base_url typo (see the FAQ below).
    curl https://api.camel-hub.com/v1/chat/completions \
      -H "Authorization: Bearer <YOUR_CAMEL_HUB_KEY>" \
      -H "Content-Type: application/json" \
      -d '{"model": "gpt-5.5", "messages": [{"role": "user", "content": "ping"}]}'

Frequently asked questions

Do I need a different SDK to call Claude or Gemini models?

No. CaMeL Hub translates every request into the target provider's native format on the server side, so the OpenAI SDK works for all of them. Keep the same client instance and only change the `model` string, e.g. `claude-sonnet-5` or `gemini-3.1-pro` instead of `gpt-5.5`.

Should base_url end in /v1 or not?

Use `https://api.camel-hub.com/v1`. The OpenAI SDK appends resource paths like `/chat/completions` to whatever you set as `base_url`, so the `/v1` segment must already be part of it β€” omitting it or adding a second one both produce 404 responses.

The SDK throws an authentication error even though curl with the same key works.

Check for an `OPENAI_API_KEY` environment variable in your shell or CI runner β€” the SDK reads it automatically and it silently overrides whatever you pass as `api_key` when both are set. Also confirm the token hasn't expired or run out of quota on the Console β†’ Token page.

Which models should I pick for a first test?

`gpt-5.5` is a solid general-purpose default, `claude-sonnet-5` is a good fit for longer reasoning-heavy tasks, and `deepseek-v4-flash` is a cheap, fast option for high-volume workloads. Browse current names and pricing in the model marketplace before committing to one in production code.