On this page
1 Overview
Global API Access URL
https://tp-api.topenrouter.vipNote: When using baseUrl in most OpenAI-compatible AI tools, you may need to append /v1 or /v1/chat/completions to the global API access address. Usage depends on the requirements of the specific tool you use.
TopenRouter provides a complete RESTful API interface. Our API is compatible with OpenAI format, allowing you to seamlessly migrate existing AI applications.
Through TopenRouter, you can uniformly call mainstream AI models such as OpenAI, Claude, and Gemini, enjoying intelligent routing, quota management, and high availability guarantees.
2 Authentication
TopenRouter API uses API Key for authentication. You can create and manage your API Key in the 'Tokens' page in the dashboard.
Authorization: Bearer YOUR_API_KEYAlways call the API from the server side, never expose your API Key.
3 Model List
Get the list of currently available models.
https://tp-api.topenrouter.vip/v1/modelsRequest Example
-H "Authorization: Bearer sk-xxxxxx"
Response Example
{
"object": "list",
"data":[
{
"id": "gpt-4",
"object": "model",
"created": 1687882411,
"owned_by": "openai"
},
{
"id": "claude-3-opus",
"object": "model",
"created": 1710323355,
"owned_by": "anthropic"
}
]
}4 Chat Dialogue
OpenAI Compatible Format
Standard chat completion interface with streaming support.
https://tp-api.topenrouter.vip/v1/chat/completionsCURL Example
curl https://tp-api.topenrouter.vip/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"model": "gpt-4",
"messages":[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello"}
],
"temperature": 0.7,
"stream": true
}'Main Parameters
model: Model ID, e.g. gpt-4, claude-3-opusmessages: Chat message list containing role and contentstream: Whether to enable streaming response, default is falsetemperature: Sampling temperature, between 0 and 2
Claude Native Format
Supports Anthropic's official message streaming format.
https://tp-api.topenrouter.vip/v1/messagesCURL Example
curl https://tp-api.topenrouter.vip/v1/messages \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello"}
]
}'Gemini Native Format
Compatible with Google AI Studio's API structure.
https://tp-api.topenrouter.vip/v1beta/models/{model}:generateContentCURL Example
curl https://tp-api.topenrouter.vip/v1beta/models/{model}:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"contents": [{
"parts": [{"text": "Hello"}]
}]
}'5 Text Completions
Traditional text completion interface for single predictions or simple content generation.
https://tp-api.topenrouter.vip/v1/completionsSupports standard parameters such as model, prompt, max_tokens.
6 Embeddings
Converts text into high-dimensional vectors for retrieval (RAG), clustering, or semantic search.
OpenAI Format
https://tp-api.topenrouter.vip/v1/embeddings{
"model": "text-embedding-3-small",
"input": "The quick brown fox"
}Gemini Format
https://tp-api.topenrouter.vip/v1/engines/{model}/embeddings{
"content": {
"parts":[{"text": "The quick brown fox"}]
}
}7 Rerank
Scores retrieved document candidates for relevance to achieve more accurate RAG results.
https://tp-api.topenrouter.vip/v1/rerankRequest JSON
{ "model": "rerank-english-v2.0", "query": "What is TopenRouter?", "documents":[ "TopenRouter is a universal AI API gateway...", "TopenRouter supports multiple model integrations..." ] }Response JSON
{ "id": "rerank-xxx", "results":[ { "index": 0, "relevance_score": 0.98 }, { "index": 1, "relevance_score": 0.85 } ] }
