Connect to iRouter with curl
Configure the API endpoint and key, choose an available model, and verify a text request.
Prepare
Create a key in the iRouter console and confirm that your balance or subscription applies to the selected line. Save the plaintext key when created. Select a Chat Completions model and replace <model-id> with its complete ID. If the catalog is empty, ask an administrator to confirm configuration.
Bash configuration and request
Set environment variables in Bash and replace the key placeholder. Query available models, then send a short request.
export IROUTER_API_BASE='https://gateway.irouter.io/v1'
export IROUTER_API_KEY='<your-irouter-api-key>'
curl --fail-with-body "$IROUTER_API_BASE/models" \
-H "Authorization: Bearer $IROUTER_API_KEY"curl --fail-with-body "$IROUTER_API_BASE/chat/completions" \
-H "Authorization: Bearer $IROUTER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"model":"<model-id>","messages":[{"role":"user","content":"Reply with a short greeting."}]}'Windows PowerShell
Use Invoke-RestMethod rather than copying Bash line continuation and JSON quoting into PowerShell. Supply your key and model ID. This example encodes the request body as UTF-8.
$env:IROUTER_API_KEY = '<your-irouter-api-key>'
$apiBase = 'https://gateway.irouter.io/v1'
$requestHeaders = @{ Authorization = "Bearer $env:IROUTER_API_KEY" }
Invoke-RestMethod -Uri "$apiBase/models" -Headers $requestHeaders
$requestBody = @{
model = '<model-id>'
messages = @(@{ role = 'user'; content = 'Reply with a short greeting.' })
} | ConvertTo-Json -Depth 8
$requestOptions = @{
Uri = "$apiBase/chat/completions"
Method = 'Post'
Headers = $requestHeaders
ContentType = 'application/json; charset=utf-8'
Body = [System.Text.Encoding]::UTF8.GetBytes($requestBody)
}
$result = Invoke-RestMethod @requestOptions
$result.choices[0].message.contentVerify
Inspect choices and the finish reason, then confirm the model, key, account, and call in usage. Generation requests may incur charges based on the actual model and line. Continue with the OpenAI SDK.
Troubleshoot
For 401, check the key and environment. For 403, check permissions, line, and IP allowlists. For 404, check the path and model. For 429, distinguish allowance from rate limits. Preserve sanitized errors instead of repeatedly submitting requests. Full troubleshooting
Fields follow OpenAI Chat Completions. Actual models and optional features depend on iRouter configuration.