1. Step 1: Set your API key

    Get your RouterHub API key. Replace PASTE_ROUTERHUB_KEY_HERE below and run in your terminal:

    macOS / Linux

    macOS / Linux
    export ROUTERHUB_API_KEY='PASTE_ROUTERHUB_KEY_HERE'

    Windows (PowerShell)

    Windows (PowerShell)
    $env:ROUTERHUB_API_KEY = 'PASTE_ROUTERHUB_KEY_HERE'

    Keep this terminal and its command history private. Never put your key in browser code or a repository.

  2. Step 2: Send a request

    Copy a model ID with Chat Completions support from Models & pricing. Replace MODEL_ID in either example below.

    Running a request uses prepaid credits. Run the cURL command in the same terminal:

    macOS / Linux

    macOS / Linux
    curl 'https://routerhub.si/v1/chat/completions' \
      -H "Authorization: Bearer $ROUTERHUB_API_KEY" \
      -H "Content-Type: application/json" \
      --connect-timeout 30 --max-time 600 -d '{"model":"MODEL_ID","messages":[{"role":"user","content":"Reply with OK."}]}'

    Windows (PowerShell)

    Windows (PowerShell)
    $body = @'
    {
      "model": "MODEL_ID",
      "messages": [
        {
          "role": "user",
          "content": "Reply with OK."
        }
      ]
    }
    '@
    $body | curl.exe 'https://routerhub.si/v1/chat/completions' `
      -H "Authorization: Bearer $env:ROUTERHUB_API_KEY" `
      -H "Content-Type: application/json" `
      --connect-timeout 30 --max-time 600 --data-binary '@-'
    Or use Python

    With Python 3 installed, save this as routerhub_request.py. No extra packages are needed.

    routerhub_request.py
    import json
    import os
    from urllib.request import Request, urlopen
    
    body = {
      "model": "MODEL_ID",
      "messages": [
        {
          "role": "user",
          "content": "Reply with OK."
        }
      ]
    }
    request = Request(
        "https://routerhub.si/v1/chat/completions",
        data=json.dumps(body).encode("utf-8"),
        headers={
            "Authorization": "Bearer " + os.environ["ROUTERHUB_API_KEY"],
            "Content-Type": "application/json",
        },
    )
    with urlopen(request, timeout=600) as response:
        print(json.load(response)["choices"][0]["message"]["content"])

    Run it in the same terminal where you set the key:

    macOS / Linux

    macOS / Linux
    python3 routerhub_request.py

    Windows (PowerShell)

    Windows (PowerShell)
    py routerhub_request.py

    Check the request in Usage. For Responses or Anthropic Messages, use the examples in the API quickstart instead.

Troubleshooting

A request times out

cURL allows 30 seconds to connect and 600 seconds for the complete request. Python uses a 600-second socket-operation timeout, not a total wall-clock deadline. These examples do not automatically retry. Check Usage and the request ID before rerunning: a local timeout does not prove that upstream work stopped.

401 or missing API key

Set ROUTERHUB_API_KEY in the same terminal before running the request. Use a RouterHub key, not a model vendor’s key.

404 or model unavailable

Replace MODEL_ID with an exact ID from Models & pricing. These examples require Chat Completions support; Responses and Messages use different request formats.

Not enough credits

Check your balance before retrying. Requests are paid from RouterHub credits, not a tool subscription.

cURL or Python is not found

Use curl.exe in Windows PowerShell. Install cURL or Python 3 if missing, then reopen your terminal and set the key again. If py is unavailable on Windows, try python.

Still stuck? Contact support.

Common questions

Do I need the OpenAI SDK?

No. The cURL example sends HTTP directly, and the Python example uses only Python’s standard library.

Can I use any RouterHub model?

These examples use Chat Completions. Choose a model supporting that API on the models page. The linked API quickstart has separate Responses and Anthropic Messages examples.