AI Gateway
AI Gateway provides OpenAI-compatible endpoints, allowing existing OpenAI SDKs or tools to call models through MaiAgent by changing only the URL and API key. These endpoints are available only under /api/v1/, and their paths do not end with /. Authentication uses Authorization: Bearer <API Key> (the key is your MaiAgent API Key, but Gateway endpoints accept only the Bearer prefix; using the Api-Key prefix returns 401). MaiAgent must enable AI Gateway for your organization. Administrators configure which models each key can call in API Key management. For full details, see the technical manual: AI Gateway: OpenAI-compatible API integration.
List available models
GET /api/v1/models
Code examples
# API call example (Shell)
curl -X GET "https://api.maiagent.ai/api/v1/models" \
-H "Authorization: Bearer YOUR_API_KEY"
# Replace YOUR_API_KEY and verify the request data before running.const axios = require('axios');
// Set request headers
const config = {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
};
axios.get("https://api.maiagent.ai/api/v1/models", config)
.then(response => {
console.log('Response received successfully:');
console.log(response.data);
})
.catch(error => {
console.error('Request error:');
console.error(error.response?.data || error.message);
});Response body
Status code: 200
Example response structure
{
"object"?: string (enum: list) // Optional
"data"?: [ // Optional
{
"id"?: string // Model ID to use in the model field when making a request (Optional)
"object"?: string (enum: model) // Optional
"created"?: integer // Unix seconds (Optional)
"owned_by"?: string // Optional
"name"?: string // Optional
"icon"?: string // Optional
"type"?: string (enum: language) // Optional
"tags"?: [ // Optional
string (enum: tool-use, multimodal, reasoning, prompt-caching, streaming)
]
"pricing"?: { // Platform models use input/output/unit=credits_per_1k_tokens/currency; organization-owned models use traffic_fee_percent/unit=percent_of_total_tokens/currency (Optional)
{
"input"?: string // Optional
"output"?: string // Optional
"traffic_fee_percent"?: string // Optional
"unit"?: string // Optional
"currency"?: string // Optional
}
}
"providers"?: [ // Optional
{
"slug"?: string // Optional
"name"?: string // Optional
"icon_url"?: string // Optional
"color"?: string // Optional
}
]
"context_window"?: integer // Only present when configured for the model (Optional)
"max_tokens"?: integer // Only present when configured for the model (Optional)
}
]
}Example response values
Status code: 4XX - Error response; X-Error-Code carries its code (see "Error codes").
Chat completions (with streaming and tool calling)
POST /api/v1/chat/completions
Request body
Request parameters
model
string
Yes
Model ID from GET /v1/models
messages
array[object]
Yes
stream
boolean
No
Returns text/event-stream when true
stream_options
object
No
stream_options.include_usage
boolean
No
temperature
number
No
max_tokens
integer
No
top_p
number
No
stop
object
No
n
integer
No
provider
object
No
provider.order
array[string]
No
Specifies backend providers; currently only the first is used
tools
array[object]
No
tool_choice
object
No
parallel_tool_calls
boolean
No
response_format
object
No
type is text, json_object, or json_schema; a json_schema object is required when using json_schema
reasoning_effort
string (enum: none, minimal, low, medium, high, xhigh, max)
No
Example request structure
Example request values
Code examples
Response body
Status code: 200 - Returns a chat.completion object when stream=false; returns SSE when stream=true
Example response structure
Example response values
Status code: 4XX - Error response; X-Error-Code carries its code (see "Error codes").
Generate text embeddings
POST /api/v1/embeddings
Request body
Request parameters
model
string
Yes
input
object
Yes
A non-empty string or an array of non-empty strings
encoding_format
string (enum: float, base64)
No
dimensions
integer
No
user
string
No
Example request structure
Example request values
Code examples
Response body
Status code: 200
Example response structure
Example response values
Status code: 4XX - Error response; X-Error-Code carries its code (see "Error codes").
Speech to Text
POST /api/v1/audio/transcriptions
Code Examples
Response
Status code: 200 - Success. When response_format is json (default), JSON is returned and usage.seconds is the number of seconds billed for this call; when it is text, text/plain; charset=utf-8 is returned and the body is the transcript
Response Schema Example
Response Example
Status code: 4XX - Error response; X-Error-Code carries its code (see "Error codes").
Text to Speech
POST /api/v1/audio/speech
Request Body
Request Parameters
model
string
Yes
Identifier of a model whose type is speech
input
string
Yes
Text to synthesize; must not be empty, up to 4,096 characters
voice
string
Yes
Must be a voice from the model's voices
response_format
string (enum: mp3, wav)
No
Must be a format from the model's response_formats; if omitted, the model's first format is used
speed
number
No
Speech speed; for current OpenAI models, 0.25 to 4.0
Request Schema Example
Request Example
Code Examples
Response
200
Success. The response body is the complete audio file (not JSON), with Content-Type audio/mpeg (mp3) or audio/wav (wav)
4XX
Error response; X-Error-Code carries its code (see "Error codes").
Last updated
Was this helpful?