Skip to content

Call an endpoint

Start only after the model is Running, its detail page shows an endpoint, and Copy as cURL contains a complete request.

  1. Create an Inference API key.

    Open API KeysGenerate API key. Choose an expiry, set Type to Self-hosted, and tick the model you want to call.

    Selecting a model authorizes its Served Model Name, not only that one resource. A replacement in the same tenant that continues using the same Served Model Name shares access; every other Served Model Name is refused. Deleting a model is not a substitute for revoking the key.

    A Platform key is the wrong credential here: it cannot call tenant self-hosted models.

    Copy the secret from the success dialog. It cannot be displayed again.

    The Generate API key dialog. Expires in reads 90 days, Type reads Self-hosted, and a checkbox list underneath offers each self-hosted model with its Served Model Name and current status.

    The model list only appears once Type is Self-hosted. A Platform key has no list, because it cannot be narrowed.

  2. Copy the tenant endpoint and Served Model Name.

    Open the model, copy the Endpoint at the top of the detail page and the model string used by Copy as cURL; it must match the model’s Served Model Name exactly.

    Do not use the model’s resource name, Hugging Face repository, or a Platform catalog Public model ID unless the generated cURL explicitly uses that same string.

    A model detail page with the endpoint shown at the top and the Copy as cURL tab open, showing a curl command whose URL is the endpoint plus /v1/chat/completions and whose body sets model to the Served Model Name.

    Two values, one screen: the endpoint at the top, and the model string inside the generated command.

  3. Set local environment variables.

    Replace both placeholders with the copied values. ONX_ENDPOINT is the tenant endpoint shown on the model detail page, without an added /v1 suffix.

    Bash or zsh

    Terminal
    export ONX_ENDPOINT="<copied-endpoint>"
    export ONX_SERVED_MODEL="<served-model-name>"

    Run the key prompt separately and paste the secret when prompted:

    Terminal
    printf "OneNexus Inference API key: "; IFS= read -rs ONX_INFERENCE_API_KEY </dev/tty && export ONX_INFERENCE_API_KEY && printf "\n"

    PowerShell

    PowerShell
    $env:ONX_ENDPOINT = "<copied-endpoint>"
    $env:ONX_SERVED_MODEL = "<served-model-name>"
    $secret = Read-Host "OneNexus Inference API key" -AsSecureString
    $env:ONX_INFERENCE_API_KEY = [System.Net.NetworkCredential]::new("", $secret).Password
    Remove-Variable secret
  4. Verify the generated request first.

    The model’s Copy as cURL command is the source of truth for the endpoint, path and model value. Do not paste the raw key into that command: it can be retained in shell history. In Bash or zsh, keep the securely read environment variable from step 3 and replace the generated command’s entire authorization header with -H "Authorization: Bearer $ONX_INFERENCE_API_KEY". Leave its other values unchanged.

    The resulting Bash/zsh request is:

    cURL
    curl "$ONX_ENDPOINT/v1/chat/completions" \
    -H "Authorization: Bearer $ONX_INFERENCE_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{
    \"model\": \"$ONX_SERVED_MODEL\",
    \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one sentence.\"}]
    }"

    API success is a 2xx response with a valid Chat Completions envelope; a complete final-answer result has a non-empty choices array and assistant content under choices[0].message.content. If final text is empty, inspect the full response before retrying; some models can return reasoning without final content.

  5. Call the same endpoint with Python.

    Install the SDK:

    Terminal
    python -m pip install openai

    Save this as endpoint_call.py and run python endpoint_call.py:

    endpoint_call.py
    import os
    from openai import OpenAI
    endpoint = os.environ["ONX_ENDPOINT"].rstrip("/")
    client = OpenAI(
    base_url=f"{endpoint}/v1",
    api_key=os.environ["ONX_INFERENCE_API_KEY"],
    )
    response = client.chat.completions.create(
    model=os.environ["ONX_SERVED_MODEL"],
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
    )
    print("Success:", response.choices[0].message.content)

    Success prints a model-generated message prefixed with Success:.

Treat these three values as one configuration unit:

  1. tenant endpoint shown on the model detail page;
  2. Inference API key authorizing that model’s Served Model Name; and
  3. exact Served Model Name.

A common failure is combining two correct values from one model with a third value from the Platform catalog or another model.

  • Keep the key in a server-side secret store or protected environment variable, never in a browser bundle or repository.
  • Set an application timeout.
  • Do not retry 401, 403, validation 4xx, or 404 unchanged.
  • Retry transient 429 or 503 responses only a bounded number of times with exponential backoff and jitter.
  • If streaming has already emitted data, do not automatically replay the whole request.

See the API reference for the request contract, or troubleshooting if the generated cURL does not succeed.