API Reference
UniKey Relay is built on the open-source NewAPI framework. For application developers, UniKey exposes AI Model APIs that are compatible with the OpenAI API format.
This page documents the caller-facing model endpoints. NewAPI also has Management APIs for administrator operations such as channel, model, token, payment, and log management; those management endpoints are not required for normal UniKey API calls.
First API request
/v1/chat/completionsREQUEST
curl -X POST "/v1/chat/completions" \ -H "Authorization: Bearer $UNIKEY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "unikey-router", "messages": [{ "role": "user", "content": "Hello Unikey" }] }'
RESPONSE
{
"choices": [{ "message": { "content": "Chat request routed." } }],
"usage": { "total_tokens": 27 }
}Base URL
https://www.getunikey.ai
Authentication
Use the API key created in the UniKey console:
Authorization: Bearer $UNIKEY_API_KEY
Most OpenAI-compatible SDKs expect the Authorization: Bearer header. Do not put the key in frontend code, browser bundles, mobile app packages, or public repositories.
OpenAI SDK example
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.UNIKEY_API_KEY,
baseURL: 'https://www.getunikey.ai/v1',
});
const response = await client.chat.completions.create({
model: 'gpt-5.2',
messages: [{role: 'user', content: 'Hello from UniKey'}],
});
console.log(response.choices[0]?.message?.content);
List models
GET /v1/models
Authorization: Bearer $UNIKEY_API_KEY
Example response:
{
"object": "list",
"data": [
{
"id": "gpt-5.2",
"object": "model",
"owned_by": "openai",
"supported_endpoint_types": ["openai", "anthropic"]
},
{
"id": "claude-sonnet-4-6",
"object": "model",
"owned_by": "anthropic",
"supported_endpoint_types": ["openai", "anthropic"]
}
]
}
Depending on client headers, the underlying NewAPI framework can adapt model-list output for OpenAI, Anthropic, or Gemini-style clients. For ordinary OpenAI-compatible usage, send Authorization: Bearer.
Chat Completions
POST /v1/chat/completions
Authorization: Bearer $UNIKEY_API_KEY
Content-Type: application/json
{
"model": "gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello UniKey"
}
],
"stream": false,
"max_tokens": 1024,
"temperature": 1
}
The endpoint is compatible with OpenAI Chat Completions. It supports common fields such as:
| Field | Type | Notes |
|---|---|---|
model | string | Model ID returned by /v1/models or listed in UniKey docs. |
messages | array | Chat messages with system, user, assistant, or tool roles. |
stream | boolean | false for JSON response, true for SSE streaming. |
temperature | number | Sampling temperature, usually between 0 and 2. |
top_p | number | Nucleus sampling, usually between 0 and 1. |
max_tokens | number | Maximum generated tokens. |
presence_penalty | number | OpenAI-compatible presence penalty. |
frequency_penalty | number | OpenAI-compatible frequency penalty. |
tools | array | Tool/function definitions for compatible models. |
tool_choice | string/object | Tool selection policy. |
Non-stream response
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"model": "gpt-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 8,
"total_tokens": 20
}
}
Streaming response
Set stream: true to receive Server-Sent Events. Each chunk follows the OpenAI-compatible streaming shape:
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
data: [DONE]
Completions
Traditional text completion endpoint:
POST /v1/completions
Authorization: Bearer $UNIKEY_API_KEY
Content-Type: application/json
{
"model": "gpt-5.2",
"prompt": "Write a one-sentence product description for UniKey."
}
Prefer Chat Completions for new integrations unless an older OpenAI-compatible client specifically requires /v1/completions.
Embeddings
POST /v1/embeddings
Authorization: Bearer $UNIKEY_API_KEY
Content-Type: application/json
{
"model": "text-embedding-ada-002",
"input": "UniKey is a unified AI capability gateway."
}
Anthropic-compatible Messages
Use /v1/messages for Anthropic-compatible clients, including Claude Code.
POST /v1/messages
x-api-key: $UNIKEY_API_KEY
Content-Type: application/json
{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"system": "You are a helpful assistant.",
"messages": [
{
"role": "user",
"content": "Hello, Claude-compatible UniKey."
}
],
"stream": false
}
If a client supports only the OpenAI SDK, use /v1/chat/completions instead.
Error response
{
"error": {
"message": "Error message",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Endpoint summary
| Endpoint | Compatibility | Purpose |
|---|---|---|
GET /v1/models | OpenAI-compatible model list | List available models. |
POST /v1/chat/completions | OpenAI Chat Completions | Main chat and agent request endpoint. |
POST /v1/completions | OpenAI legacy completions | Legacy prompt completion clients. |
POST /v1/embeddings | OpenAI embeddings | Text-to-vector embedding generation. |
POST /v1/messages | Anthropic-compatible | Claude-style clients such as Claude Code. |