Step 5: Common Usage
Step 5: Common Usage
After completing the configuration, you can use NiceRouter services by replacing the API's base_url.
API Base URL
NiceRouter's API base URL is:
https://api.nicerouter.comUsing in Software
Many software applications that support AI features allow you to customize the service address and API Key. You can directly configure NiceRouter in these applications.
General Configuration Parameters
In software that supports custom AI services, you typically need to configure the following parameters:
- API Key: Your NiceRouter Token created in Step 4
- Base URL / API Address:
https://api.nicerouter.com/v1 - Model Name: Select according to your needs, such as
gpt-4,claude-3-opus-20240229, etc.
Common Software Configuration Examples
Software Supporting OpenAI-Compatible API and Other Common Models
Most software that supports OpenAI-compatible APIs can be configured as follows:
- Find the "Custom API" or "Custom Service" option
- Enter API address:
https://api.nicerouter.com/v1 - Enter API Key: Your NiceRouter Token
- Select or enter model name
Tip
The configuration interface may vary slightly between different software, but the core configuration items (API address, API Key, model name) are universal.
Using in Code
Here are configuration examples for common programming languages and SDKs:
OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key="your-nicerouter-token", # Replace with your NiceRouter Token
base_url="https://api.nicerouter.com/v1" # Replace base_url
)
# Usage example
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": "Hello!"}
]
)Anthropic SDK
from anthropic import Anthropic
client = Anthropic(
api_key="your-nicerouter-token", # Replace with your NiceRouter Token
base_url="https://api.nicerouter.com/v1" # Replace base_url
)
# Usage example
message = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello!"}
]
)Node.js (OpenAI SDK)
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'your-nicerouter-token', // Replace with your NiceRouter Token
baseURL: 'https://api.nicerouter.com/v1' // Replace baseURL
});
// Usage example
const completion = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
});cURL Example
curl https://api.nicerouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-nicerouter-token" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'Environment Variables Configuration
You can also configure via environment variables:
# .env file
OPENAI_API_KEY=your-nicerouter-token
OPENAI_BASE_URL=https://api.nicerouter.com/v1Then use in your code:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
base_url=os.getenv("OPENAI_BASE_URL")
)Tip
- Replace
your-nicerouter-tokenwith the API token you created in Step 4 - Ensure the token group matches the service you want to use
- For more API usage examples, please refer to the API Documentation