For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Returns the identifiers and pricing of models accessible with this key. For identifier conventions, see Model identifiers in the technical guide.

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

The request and response formats match OpenAI chat/completions (model, messages, stream, tools, etc.); the platform schema does not list these fields. For parameters and examples, see Chat completion parameters and Minimal examples in the technical guide.

Request body

Request parameters

Field
Type
Required
Description

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

The request and response formats match OpenAI embeddings (model, input). For examples, see Embeddings in the technical guide.

Request body

Request parameters

Field
Type
Required
Description

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

Upload a complete audio file to get a transcript (synchronous call; streaming is not supported). The request body is multipart/form-data: file is required. It is the audio file, up to 25 MB, with the format determined by the file extension; mp3, mp4, mpeg, mpga, m4a, wav, and webm are accepted. model is required; use a model whose type is transcription (for example openai/gpt-transcribe or azure/speech-to-text). language is optional, for example zh; if omitted, the model detects it automatically. response_format is optional: json (default) or text. With text, the response is a text/plain transcript instead of JSON. For the rules of language and for fields that only some models support or that accept a single value only (prompt, temperature, stream), see Speech to Text in the technical manual. Billing is per second based on the audio duration reported by the provider, rounded up to the next whole second with a minimum of 1 second; see Usage and Credits billing. An API Key with a model allowlist cannot use speech models (returns 404 model_not_found), and organizations on a per-character billing plan cannot use them (returns 403); see Available speech models. For timeouts, errors, and cases where no credits are deducted, see Common behavior of speech endpoints.

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

Send text to get a complete audio file (synchronous call; streaming is not supported). The request body is JSON: model is required; use a model whose type is speech (for example openai/gpt-4o-mini-tts). input is required, must not be empty, and is limited to 4,096 characters. voice is required and must be one of the voices the model lists in GET /api/v1/models (for example alloy). response_format is optional, mp3 or wav; if omitted, the model's first format is used. speed is optional; for current OpenAI models it ranges from 0.25 to 4.0. For instructions, which only some models support, and stream_format, which only accepts audio, see Text to Speech in the technical manual. The response body is the audio file itself (audio/mpeg or audio/wav), not JSON; the sample code saves it to a file. Billing is per 1,000 characters of input; see Usage and Credits billing. The API Key allowlist and per-character billing plan restrictions are the same as for speech to text; see Available speech models. For timeouts and errors, see Common behavior of speech endpoints; for call limits, see Limits.

Request Body

Request Parameters

Field
Type
Required
Description

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

Status Code
Description

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?