REST API
Call any aixplain agent, model or tool over HTTP with your API key, from any language.
The Python tabs use the SDK, which wraps the same endpoints. To connect from an MCP client instead, see MCP servers.
Authentication
Send your API key in the x-api-key header. Requests with a body also need Content-Type: application/json.
x-api-key: YOUR_API_KEY
Content-Type: application/json
Use the workspace API key from the aixplain app, and keep it on your server, never in browser code. Every request counts toward your workspace's Rate limiting.
How execution works
Fast models return the result in the POST response, with "completed": true. Agents and slow models, such as video generation, return a polling URL in data instead:
{
"status": "IN_PROGRESS",
"completed": false,
"data": "https://models.aixplain.com/api/v1/data/<REQUEST_ID>"
}
| Field | Meaning |
|---|---|
status | IN_PROGRESS, SUCCESS or FAILED. |
completed | false while running, true once finished. |
data | While running, the URL to poll. Once finished, the result. |
GET the URL in data every few seconds until completed is true. Poll the exact URL you receive, because the host and version differ by service.
Run an asset
Pick a language once; the tabs stay in sync across the page.
Agents
- Python
- curl
- Fetch
- Axios
- MCP
from aixplain import Aixplain
aix = Aixplain(api_key="YOUR_API_KEY")
AGENT_ID = "YOUR_AGENT_ID" # from agent.id
agent = aix.Agent.get(AGENT_ID)
result = agent.run("What is 5 + 5?")
print(result.data.output)
curl -X POST "https://platform-api.aixplain.com/v2/agents/YOUR_AGENT_ID/run" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "What is 5 + 5?"}'
The response holds the polling URL in data. See Run an agent.
const headers = { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" };
const start = await fetch("https://platform-api.aixplain.com/v2/agents/YOUR_AGENT_ID/run", {
method: "POST",
headers,
body: JSON.stringify({ query: "What is 5 + 5?" }),
}).then((r) => r.json());
let result;
do {
await new Promise((resolve) => setTimeout(resolve, 2000));
result = await fetch(start.data, { headers }).then((r) => r.json());
} while (!result.completed);
console.log(result.data.output);
import axios from "axios";
const headers = { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" };
const { data: start } = await axios.post(
"https://platform-api.aixplain.com/v2/agents/YOUR_AGENT_ID/run",
{ query: "What is 5 + 5?" },
{ headers },
);
let result;
do {
await new Promise((resolve) => setTimeout(resolve, 2000));
({ data: result } = await axios.get(start.data, { headers }));
} while (!result.completed);
console.log(result.data.output);
{
"mcpServers": {
"aixplain_agent": {
"url": "https://models-mcp.aixplain.com/agent/mcp/YOUR_AGENT_ID",
"headers": {
"Authorization": "Bearer YOUR_API_KEY",
"Accept": "application/json, text/event-stream"
}
}
}
}
See Call an agent over MCP for the tool's inputs and result.
Models
- Python
- curl
- Fetch
- Axios
- MCP
from aixplain import Aixplain
aix = Aixplain(api_key="YOUR_API_KEY")
model = aix.Model.get("openai/gpt-4o-mini/openai")
result = model.run(text="What is 2 + 2?")
print(result.data)
curl -X POST "https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "What is 2 + 2?"}'
const res = await fetch("https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai", {
method: "POST",
headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
body: JSON.stringify({ text: "What is 2 + 2?" }),
}).then((r) => r.json());
console.log(res.data);
import axios from "axios";
const { data } = await axios.post(
"https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai",
{ text: "What is 2 + 2?" },
{ headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" } },
);
console.log(data.data);
{
"mcpServers": {
"gpt_5_4": {
"url": "https://models-mcp.aixplain.com/mcp/openai%2Fgpt-5.4%2Fopenai",
"headers": {
"Authorization": "Bearer YOUR_API_KEY",
"Accept": "application/json, text/event-stream"
}
}
}
}
See MCP servers for client setup.
The execute endpoint takes an asset ID or a URL-encoded asset path. Inputs differ by model type; see Run a model and the sections after it.
Tools
- Python
- MCP
from aixplain import Aixplain
aix = Aixplain(api_key="YOUR_API_KEY")
tool = aix.Tool.get("tavily/tavily-web-search/tavily")
result = tool.run(action="search", data={"query": "latest AI news"})
print(result.data)
{
"mcpServers": {
"tavily": {
"url": "https://models-mcp.aixplain.com/mcp/tavily%2Ftavily-web-search%2Ftavily",
"headers": {
"Authorization": "Bearer YOUR_API_KEY",
"Accept": "application/json, text/event-stream"
}
}
}
}
A tool's actions and inputs differ per tool. List them with tool.actions, or copy snippets from the tool's card in the Marketplace.
Run a model
POST https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "What is 2 + 2?"
}
{
"status": "SUCCESS",
"completed": true,
"data": "2 + 2 equals 4.",
"details": [{"index": 0, "message": {"role": "assistant", "content": "2 + 2 equals 4."}, "finish_reason": "stop"}],
"runTime": 0.502,
"usedCredits": 7.05e-06,
"usage": {"prompt_tokens": 15, "completion_tokens": 8, "total_tokens": 23},
"asset": {"assetId": "669a63646eb56306647e1091", "id": "openai/gpt-4o-mini/openai"}
}
| Field | Type | Description |
|---|---|---|
data | string | The model's answer, or the polling URL for async jobs. |
details | array | The provider's message objects, with role, content and finish_reason. |
usage | object | Token counts. |
usedCredits | number | Credits charged for the call. |
runTime | number | Server-side run time in seconds. |
asset | object | The model that ran, by ID and path. |
To also get the provider's unmodified response, add "options": {"includeRawData": true} to the body and read the top-level rawData field.
Set model parameters
Pass parameters as top-level fields next to text:
POST https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "What are the colors of the rainbow?",
"max_tokens": 20,
"temperature": 0.8
}
Each model accepts its own parameters. Get them from the model's definition:
GET https://platform-api.aixplain.com/v2/models/669a63646eb56306647e1091
x-api-key: YOUR_API_KEY
The params array lists each parameter's name, required, dataType, availableOptions and defaultValues.
Stream LLM output
Add "stream": true to get tokens as server-sent events. Each event is a data: line with an OpenAI-style chat.completion.chunk, and the stream ends with data: [DONE].
POST https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "Count to 3.",
"stream": true
}
data: {"choices": [{"index": 0, "delta": {"role": "assistant", "content": ""}, "finish_reason": null}]}
data: {"choices": [{"index": 0, "delta": {"content": "1"}, "finish_reason": null}]}
...
data: {"choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}
data: {"choices": [], "usage": {"prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20}}
data: [DONE]
Read the text from choices[0].delta.content. The last event before [DONE] carries usage.
Send chat history and images
For a conversation, pass a list of role and content messages as text. A message's content can also be a list of text and image_url parts for vision models such as GPT-4o Mini.
POST https://models.aixplain.com/api/v2/execute/openai%2Fgpt-4o-mini%2Fopenai
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": [
{
"role": "user",
"content": [
{"type": "text", "text": "What animal is in this image? One word."},
{"type": "image_url", "image_url": {"url": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"}}
]
}
],
"max_tokens": 10
}
The response's data is "Cat.". The provider downloads image URLs, so they must be public. To send an image you do not host, use a base64 data URI as the url, such as data:image/png;base64,iVBORw0KGgo....
Speech and video models
Text-to-speech models take text and return a signed, time-limited URL to the audio in data:
POST https://models.aixplain.com/api/v2/execute/618ba6e4e2e1a9153ca2a3a2
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "The quick brown fox jumps over the lazy dog."
}
Speech recognition models take an audio URL in source_audio and the spoken language. Pass the URL from the text-to-speech response to transcribe it:
POST https://models.aixplain.com/api/v2/execute/615dd18b6eb56373643b09d1
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"language": "en",
"source_audio": "AUDIO_URL"
}
{
"status": "SUCCESS",
"completed": true,
"data": "the quick brown fox jumps over the lazy dog",
"confidence": 0.955996,
"details": {"segments": [{"segment_id": 0, "start_time": 0.1, "end_time": 3.4, "text": "the quick brown fox jumps over the lazy dog", "confidence": 0.955996, "speaker": ""}]}
}
Video generation models, such as Seedance 1.5 pro (695ea397253de54a56dc5aa1), run asynchronously. Send the prompt in text, plus optional resolution, ratio and duration, then poll until data holds the video URL.
Upload a file
The execute endpoint reads media from URLs. To send a local file, upload it to temporary storage, then pass the returned downloadUrl to the model.
-
Request an upload URL:
POST https://platform-api.aixplain.com/sdk/file/upload/temp-urlx-api-key: YOUR_API_KEYContent-Type: application/x-www-form-urlencodedcontentType=audio/wav&originalName=greeting.wavThe response has
name,key,uploadUrl,downloadUrlandheaders. -
PUTthe file touploadUrl, with the sameContent-Typeyou declared:curl -X PUT 'UPLOAD_URL' -H 'Content-Type: audio/wav' --data-binary @greeting.wav -
Pass
downloadUrlto the model, for example assource_audio.
| File type | Upload limit |
|---|---|
| Audio | 50 MB |
| Image | 25 MB |
Documents (application/*) | 25 MB |
| Video | 300 MB |
Database (.db, .sqlite, .sqlite3) | 300 MB |
| Other | 50 MB |
A model can set tighter format or length limits; check its card in the Marketplace.
Run an agent
Agent runs are always asynchronous. Send query as a top-level field:
POST https://platform-api.aixplain.com/v2/agents/{agent_id}/run
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"query": "What is 5 + 5?"
}
{
"requestId": "1-bcb3388c-8df0-46f3-a48b-0807fdab96f9",
"data": "https://platform-api.aixplain.com/sdk/agents/1-bcb3388c-8df0-46f3-a48b-0807fdab96f9/result"
}
Poll the URL in data until completed is true:
GET https://platform-api.aixplain.com/sdk/agents/{request_id}/result
x-api-key: YOUR_API_KEY
{
"completed": true,
"status": "SUCCESS",
"data": {
"input": "What is 5 + 5?",
"output": "10",
"steps": [...],
"runTime": 1.86,
"usedCredits": 0.001563,
...
}
}
The answer is in data.output, and data.steps lists every model and tool call. Stop polling when status is SUCCESS or FAILED.
Multi-turn conversations
To keep context across turns, create a session for the agent, then post each user message to it. This is the REST form of Sessions and memory.
POST https://platform-api.aixplain.com/v1/sessions
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"agentId": "YOUR_AGENT_ID",
"name": "Support chat"
}
The response's id is the session ID. Post each message to the session:
POST https://platform-api.aixplain.com/v1/sessions/{session_id}/messages
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"role": "user",
"content": "My name is Sam."
}
The response has a requestId. Poll https://platform-api.aixplain.com/sdk/agents/{request_id}/result for the answer, as in Run an agent. A later message such as "What is my name?" gets "Your name is Sam."
GET /v1/sessions/{session_id}/messages returns the transcript, and DELETE /v1/sessions/{session_id} deletes the session.
To keep the conversation on your side instead, send earlier turns in history on each run:
{
"query": "What is my name?",
"history": [
{"role": "user", "content": "My name is Sam."},
{"role": "assistant", "content": "Nice to meet you, Sam."}
]
}
Call an agent over MCP
Every agent is also served as a hosted MCP server with a single tool. Connect from any MCP client that supports a remote server with a Bearer header.
POST https://models-mcp.aixplain.com/agent/mcp/{agent_id}
Authorization: Bearer YOUR_API_KEY
Accept: application/json, text/event-stream
x-api-key: YOUR_API_KEY also works in place of Authorization. Requests without the Accept header are rejected with 406.
Use the 24-character agent ID in the URL. Path-style identifiers such as supplier/agent-name work for models and tools but not for agents.
tools/list returns one tool, named after the agent's path (for example aixplain/copywriter/aixplain), with these inputs:
| Input | Required | Purpose |
|---|---|---|
query | Yes | The request for the agent. |
sessionId | No | Continues a server-managed session. See Multi-turn conversations. |
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "aixplain/copywriter/aixplain",
"arguments": {"query": "Reply with exactly the single word: OK"}
}
}
The server waits for the run to finish and returns:
{
"content": [],
"structuredContent": {
"status": "SUCCESS",
"data": "OK",
"requestId": "ced03ab3-..."
}
}
The agent's answer is in structuredContent.data, and content is empty. MCP clients that display only content may show an empty tool result.
Errors
| Status | Cause | Example body |
|---|---|---|
400 | Malformed body or missing field, such as query nested inside data | {"message":["query should not be empty"],"error":"Bad Request","statusCode":400} |
401 | Missing or invalid API key on a model call | {"error":"Invalid api key. Please generate a new api key and try again."} |
403 | Missing or invalid API key on an agent call | {"message":"Forbidden resource","error":"Forbidden","statusCode":403} |
492 | The input URL could not be downloaded | {"error":"err.invalid_input_data_or_input_url"} |
A model call can also return HTTP 201 with "status": "FAILED" when the provider rejects the input, and an async run can finish FAILED after it starts. Always check the final status, not only the HTTP code.
Next steps
- MCP servers: connect models and tools to any MCP client.
- API keys: create scoped keys for each app.
- Rate limiting: cap requests, tokens and credits per key.