cURL Examples
Use NemoRouter with cURL from the command line
cURL Examples
cURL is the fastest way to test NemoRouter from the command line. Every example on this page is copy-paste ready — just set your API key and go.
Setup
Set your API key as an environment variable:
export NEMOROUTER_API_KEY="sk-nemo-your-key-here"All examples below reference $NEMOROUTER_API_KEY. Make sure it's set in your shell before running them.
Chat Completions
Basic Chat
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "What is an LLM gateway?"}
]
}'With System Message
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a concise technical writer. Answer in 2-3 sentences."},
{"role": "user", "content": "Explain API rate limiting."}
],
"temperature": 0.5,
"max_tokens": 256
}'Multi-Turn Conversation
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a high-level, interpreted programming language known for its simplicity and readability."},
{"role": "user", "content": "What are its main use cases?"}
]
}'Using Different Models
Switch providers by changing the model field:
# Anthropic Claude
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-4-sonnet",
"messages": [
{"role": "user", "content": "Write a haiku about cloud computing."}
]
}'# Google Gemini
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"messages": [
{"role": "user", "content": "What are the key differences between REST and GraphQL?"}
]
}'# Meta Llama
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "llama-4-scout",
"messages": [
{"role": "user", "content": "Explain microservices architecture."}
]
}'Streaming
Stream the response token by token using server-sent events:
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Write a short poem about APIs."}
],
"stream": true
}'Each line in the response is a server-sent event:
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"In"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" circuits"},"finish_reason":null}]}
data: [DONE]JSON Mode
Force the model to output valid JSON:
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You output JSON. Return a list of 3 colors with name and hex fields."},
{"role": "user", "content": "Give me colors."}
],
"response_format": {"type": "json_object"}
}'Function Calling
Define tools for the model to call:
curl https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "What is the weather in Tokyo?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name, e.g. Tokyo, Japan"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'Embeddings
Single Text
curl https://api.nemorouter.ai/v1/embeddings \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "NemoRouter is an enterprise LLM gateway."
}'Batch Embeddings
curl https://api.nemorouter.ai/v1/embeddings \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"First document about AI gateways.",
"Second document about API management.",
"Third document about cost optimization."
]
}'Custom Dimensions
curl https://api.nemorouter.ai/v1/embeddings \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-large",
"input": "NemoRouter simplifies LLM access.",
"dimensions": 256
}'List Models
List all available models:
curl https://api.nemorouter.ai/v1/models \
-H "Authorization: Bearer $NEMOROUTER_API_KEY"Pretty-Print with jq
curl -s https://api.nemorouter.ai/v1/models \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" | jq '.data[] | .id'Get a Specific Model
curl https://api.nemorouter.ai/v1/models/gpt-4o \
-H "Authorization: Bearer $NEMOROUTER_API_KEY"Useful cURL Flags
| Flag | Purpose | Example |
|---|---|---|
-s | Silent mode (no progress bar) | curl -s https://... |
-v | Verbose (show headers) | curl -v https://... |
-o file.json | Save response to file | curl -o response.json https://... |
-w "\n" | Add trailing newline | curl -w "\n" https://... |
--max-time 30 | Timeout after 30 seconds | curl --max-time 30 https://... |
View Response Headers
Use -v or -i to see NemoRouter's response headers:
curl -i https://api.nemorouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}]
}'Look for NemoRouter-specific headers in the response:
x-nemo-org-id: your-org-uuid
x-nemo-key-alias: sk-...xxxxShell Script Example
A complete shell script that calls NemoRouter:
#!/bin/bash
set -euo pipefail
# Check for API key
if [ -z "${NEMOROUTER_API_KEY:-}" ]; then
echo "Error: NEMOROUTER_API_KEY is not set"
exit 1
fi
BASE_URL="https://api.nemorouter.ai/v1"
MODEL="${1:-gpt-4o}"
PROMPT="${2:-Hello, NemoRouter!}"
echo "Model: $MODEL"
echo "Prompt: $PROMPT"
echo "---"
curl -s "$BASE_URL/chat/completions" \
-H "Authorization: Bearer $NEMOROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d "$(cat <<EOF
{
"model": "$MODEL",
"messages": [{"role": "user", "content": "$PROMPT"}],
"max_tokens": 256
}
EOF
)" | jq -r '.choices[0].message.content'Usage:
chmod +x nemo-chat.sh
./nemo-chat.sh gpt-4o "What is NemoRouter?"
./nemo-chat.sh claude-4-sonnet "Write a haiku about APIs."Error Responses
Common errors you'll encounter:
401 Unauthorized
{
"error": {
"message": "Invalid API key provided.",
"type": "authentication_error",
"code": "invalid_api_key"
}
}Fix: Check that $NEMOROUTER_API_KEY is set and valid.
402 Payment Required
{
"error": {
"message": "Insufficient credits.",
"type": "billing_error",
"code": "insufficient_credits"
}
}Fix: Add credits from the Billing page in your dashboard.
429 Too Many Requests
{
"error": {
"message": "Rate limit exceeded.",
"type": "rate_limit_error",
"code": "rate_limit_exceeded"
}
}Fix: Wait and retry, or upgrade your plan for higher rate limits.
Next Steps
- Python SDK — Python integration guide
- Node.js SDK — Node.js integration guide
- Chat Completions API — Full API reference
- Authentication — API key management