API requests
This guide provides comprehensive examples for interacting with aiXplain's API endpoints across Models, Tools, and Agents.
This guide provides examples for interacting with aiXplain's production API endpoints.
Authentication
All API requests require an API key in the request header:
x-api-key: YOUR_API_KEY
Content-Type: application/json
Models API
Base URL: https://models.aixplain.com
Run model
Request:
POST https://models.aixplain.com/api/v2/execute/{model_id}
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "What is 2 + 2?"
}
Run with parameters
Request:
POST https://models.aixplain.com/api/v2/execute/{model_id}
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": "What are the colors of the rainbow?",
"max_tokens": 10,
"temperature": 0.8
}
Run with chat history
Request:
POST https://models.aixplain.com/api/v2/execute/{model_id}
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"text": [
{"role": "user", "content": "Hello!"},
{"role": "assistant", "content": "Hi there! How can I help?"},
{"role": "user", "content": "Tell me a fun fact."}
]
}
Poll for result (if needed)
Some models return a requestId for polling:
Request:
GET https://models.aixplain.com/api/v2/data/{request_id}
x-api-key: YOUR_API_KEY
Tools API
Base URL: https://models.aixplain.com
Run tool
Request:
POST https://models.aixplain.com/api/v2/execute/{tool_id}
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"action": "scrape",
"data": {
"url": "https://example.com"
}
}
Poll for result
Request:
GET https://models.aixplain.com/api/v2/data/{request_id}
x-api-key: YOUR_API_KEY
Agents API
Base URL: https://platform-api.aixplain.com
Run agent
Request:
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?"
}
Poll for result
Request:
GET https://platform-api.aixplain.com/sdk/agents/{request_id}/result
x-api-key: YOUR_API_KEY
Multi-turn conversation (with session)
Request:
POST https://platform-api.aixplain.com/v2/agents/{agent_id}/run
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"query": "What was my previous question?",
"sessionId": "SESSION_ID_FROM_PREVIOUS_RESPONSE"
}
Multi-turn conversation (with history)
Request:
POST https://platform-api.aixplain.com/v2/agents/{agent_id}/run
x-api-key: YOUR_API_KEY
Content-Type: application/json
{
"query": "Continue from where we left off",
"history": [
{"role": "user", "content": "Help me plan a project"},
{"role": "assistant", "content": "Sure! What kind of project?"}
]
}