Release candidate · 0.4.0
Build with the Max API
Use Max agents, files, tasks, teams and Code projects from JavaScript or Python.
Quickstart
Use Node.js 20 or newer, or Python 3.10 or newer. In Max, create a scoped API key with usage:read. Set
MAX_API_KEY in your server environment and set MAX_API_URL to your Max API origin.
For TEST the API URL is https://test.elmax.ai/api/max.
Public npm and PyPI packages are pending. To run these examples now, install the matching JavaScript tarball or Python wheel if you have a release candidate.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.getAccountUsage({});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.get_account_usage(**{})
print(result)The response provides the current account usage window, settled costs and pending reservations. Monetary values are decimal strings. Use the indicated window when displaying usage.
Choose a credential
- Public. Call these reads without a credential.
- Scoped API key. Use a server key with the scopes listed on each operation. Ownership and resource access still apply.
- Verified Max session. Max's signed-in products supply a fresh user token. A user ID alone carries no authority.
- App grant. Use an explicit grant for the permitted state and asset calls. The grant is limited to its project, audience and lifetime.
Guides
Create and talk to an agent
Use a scoped server key with agents:write to create the agent and agents:read to discover it. Add chat:completions for paid execution. Set MAX_AGENT_ID to the returned agent ID. Read the account usage after an execution, and keep the key in your server environment.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.postV1Agents({
"body": {
"name": "Support helper",
"description": "Answers common account questions.",
"system_prompt": "Answer help questions clearly. Ask for clarification when necessary."
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.post_v1_agents(**{'body': {'name': 'Support helper',
'description': 'Answers common account questions.',
'system_prompt': 'Answer help questions clearly. Ask for clarification '
'when necessary.'}})
print(result)Read and resume a conversation
Use sessions:read with an agent you can access. Save the conversation ID from a completed response. Load the conversation's stored messages before continuing, and keep one explicit application request per user turn. If the stream ends early, reconcile recorded messages before submitting another paid request.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.getV1AgentsAgentIdSessions({
"path": {
"agent_id": "agt_example"
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.get_v1_agents_agent_id_sessions(**{'path': {'agent_id': 'agt_example'}})
print(result)Upload and retrieve workspace files
Use files:write for upload and files:read for listing and retrieval. The upload request uses the documented filename, MIME type and base64-encoded bytes. Reuse the returned document ID to retrieve content. Place synthetic inputs in a separate test workspace when trying write operations.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.postV1FileManagerFiles({
"body": {
"file_name": "example",
"mime_type": "text/plain",
"content_base64": "SGVsbG8hCg=="
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.post_v1_file_manager_files(**{'body': {'file_name': 'example',
'mime_type': 'text/plain',
'content_base64': 'SGVsbG8hCg=='}})
print(result)Start a team run and recover the result
Discover a published team from a workspace where your key has access. Pin each input revision and keep one submission ID for a case. After the accepted response, save the run ID, then read progress and outputs. Use the documented cancellation operation only for runs you are authorized to control.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.getGroupsGroupIdAiTeams({
"path": {
"group_id": "grp_example"
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.get_groups_group_id_ai_teams(**{'path': {'group_id': 'grp_example'}})
print(result)Create a Max Code project and work with source
Use code:project:write to create or import an editable project. Read it with code:project:read. Use the same request key if the response to creation is interrupted. Keep the returned project ID and the current workspace revision when saving edits. A revision conflict means you should load the latest draft and reconcile your files before saving.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.postV1MaxCodeProjects({
"body": {
"title": "Support dashboard",
"stack": "vanilla",
"idempotency_key": "support-example-001"
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.post_v1_max_code_projects(**{'body': {'title': 'Support dashboard',
'stack': 'vanilla',
'idempotency_key': 'support-example-001'}})
print(result)Manage group tasks
Use a verified caller with groups:write and access to the group. Create a task and save its task ID. Read the group's tasks with groups:read, then update the task by ID. An agent or team execution has its own run ID and status operations.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.postGroupsGroupIdTasks({
"path": {
"group_id": "grp_example"
},
"body": {
"title": "Welcome"
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.post_groups_group_id_tasks(**{'path': {'group_id': 'grp_example'}, 'body': {'title': 'Welcome'}})
print(result)Work with project assets and state
Use a project-bound key or a reviewed short-lived grant when the operation lists that credential. Copy the exact project ID. A grant requires the app's audience header and the matching runtime origin in browser use. Save the returned state version and use it to guard the next update.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
const result = await max.api.getV1MaxCodeProjectsProjectIdAssets({
"path": {
"project_id": "icp_example"
}
});
console.log(result);import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max:
result = max.api.get_v1_max_code_projects_project_id_assets(**{'path': {'project_id': 'icp_example'}})
print(result)Stream an agent response
Set MAX_AGENT_ID to an agent you can run. Observe text deltas until completion.
The SDK reports a truncated stream as an error. Check the conversation before retrying a paid call.
import { MaxClient } from "@elmax/api";
const max = new MaxClient({
baseURL: process.env.MAX_API_URL,
apiKey: process.env.MAX_API_KEY,
});
for await (const chunk of max.chat.completions.stream({
model: process.env.MAX_AGENT_ID,
messages: [{ role: "user", content: "Explain how to reset my password." }],
})) {
for (const choice of chunk.choices ?? []) {
process.stdout.write(choice.delta?.content ?? "");
}
}import os
from elmax_ai import MaxClient
with MaxClient(base_url=os.environ["MAX_API_URL"], api_key=os.environ["MAX_API_KEY"]) as max_api:
for chunk in max_api.chat.completions.stream({
"model": os.environ["MAX_AGENT_ID"],
"messages": [{"role": "user", "content": "Explain how to reset my password."}],
}):
for choice in chunk.get("choices", []):
print(choice.get("delta", {}).get("content", ""), end="", flush=True)Use a Max agent in a Max Code app
Connect a workspace agent to an eligible project, test the connection, then publish an app for signed-in visitors. Each invocation runs against the app's approved agent and creator budget.
Available when the app-agent capability is enabled in your environment.
- Ask the creator to connect an agent in Project → Agents and use its exact approved alias.
- Use window.MaxAgents.run(alias, {message, requestId}) only when the host provides it.
- Reuse a requestId for a retry of the same message. Generate a new ID for a new message.
- Handle unavailable, sign-in, budget and revocation errors at the call site.
- The editor preview returns a deterministic fixture. Test a real call explicitly in Project → Agents.
- Published calls require a signed-in audience and an owner-approved release connection with a budget.
- Keep platform credentials on the server. Treat agent output as text.
const requestId = crypto.randomUUID();
const reply = await window.MaxAgents.run("support", {
message: "How do I reset my password?",
requestId,
});
document.querySelector("#answer").textContent = reply.text;
The same runtime example is available to the Max Code authoring assistant.
API reference
121 reviewed operations
AI Team files
- GETList Group Files
/groups/{group_id}/ai-teams/files - PUTPut Group File
/groups/{group_id}/ai-teams/files - GETRead Group File
/groups/{group_id}/ai-teams/files/content - POSTMove Group File
/groups/{group_id}/ai-teams/files/move - GETList Group File Revisions
/groups/{group_id}/ai-teams/files/revisions - GETList Team Outputs
/groups/{group_id}/ai-teams/{team_id}/outputs - GETWorkspace List Group Files
/workspaces/{workspace_id}/ai-teams/files - PUTWorkspace Put Group File
/workspaces/{workspace_id}/ai-teams/files - GETWorkspace Read Group File
/workspaces/{workspace_id}/ai-teams/files/content - POSTWorkspace Move Group File
/workspaces/{workspace_id}/ai-teams/files/move - GETWorkspace List Group File Revisions
/workspaces/{workspace_id}/ai-teams/files/revisions - GETWorkspace List Team Outputs
/workspaces/{workspace_id}/ai-teams/{team_id}/outputs
AI Teams
- GETList Teams
/groups/{group_id}/ai-teams - GETGet Team
/groups/{group_id}/ai-teams/{team_id} - GETList Runs
/groups/{group_id}/ai-teams/{team_id}/runs - POSTStart
/groups/{group_id}/ai-teams/{team_id}/runs - GETGet Run
/groups/{group_id}/ai-teams/{team_id}/runs/{run_id} - POSTCancel
/groups/{group_id}/ai-teams/{team_id}/runs/{run_id}/cancel - GETEvents
/groups/{group_id}/ai-teams/{team_id}/runs/{run_id}/events - GETReceipt
/groups/{group_id}/ai-teams/{team_id}/runs/{run_id}/receipts/{name} - GETWorkspace List Teams
/workspaces/{workspace_id}/ai-teams - GETWorkspace Get Team
/workspaces/{workspace_id}/ai-teams/{team_id} - GETWorkspace List Runs
/workspaces/{workspace_id}/ai-teams/{team_id}/runs - POSTWorkspace Start
/workspaces/{workspace_id}/ai-teams/{team_id}/runs - GETWorkspace Get Run
/workspaces/{workspace_id}/ai-teams/{team_id}/runs/{run_id} - POSTWorkspace Cancel
/workspaces/{workspace_id}/ai-teams/{team_id}/runs/{run_id}/cancel - GETWorkspace Events
/workspaces/{workspace_id}/ai-teams/{team_id}/runs/{run_id}/events - GETWorkspace Receipt
/workspaces/{workspace_id}/ai-teams/{team_id}/runs/{run_id}/receipts/{name}
Agents
- GETList Agents
/v1/agents - POSTCreate Agent
/v1/agents - GETList Public Agents Catalog
/v1/agents/public - GETCheck Slug Availability
/v1/agents/slug-availability - DELETEDelete Agent
/v1/agents/{agent_id} - GETGet Agent
/v1/agents/{agent_id} - PUTUpdate Agent
/v1/agents/{agent_id} - GETList Agent Sessions
/v1/agents/{agent_id}/sessions - DELETEDelete Agent Session
/v1/agents/{agent_id}/sessions/{session_id} - PUTRename Agent Session
/v1/agents/{agent_id}/sessions/{session_id} - GETGet Agent Session Messages
/v1/agents/{agent_id}/sessions/{session_id}/messages
Assets
Chat Completions
Documents
- GETList Session Files
/v1/agents/{agent_id}/sessions/{session_id}/files - GETList Documents
/v1/documents - POSTCreate Document
/v1/documents - DELETEDelete Document
/v1/documents/{document_id} - GETGet Document Content
/v1/documents/{document_id}/content - GETFile Manager List Files
/v1/file-manager/files - POSTFile Manager Upload File
/v1/file-manager/files - DELETEFile Manager Delete File
/v1/file-manager/files/{document_id} - PATCHFile Manager Rename File
/v1/file-manager/files/{document_id} - GETFile Manager Get File Content
/v1/file-manager/files/{document_id}/content
Google Auth
Groups
- GETListing
/groups - POSTCreate
/groups - GETDetail
/groups/{group_id} - PUTPage
/groups/{group_id}/page - POSTAdd Task
/groups/{group_id}/tasks - PUTEdit Task
/groups/{group_id}/tasks/{task_id} - GETWorkspace
/groups/{group_id}/workspace - GETFile Content
/groups/{group_id}/workspace/files/{document_id} - POSTStart Run
/groups/{group_id}/workspace/runs - GETRun Result
/groups/{group_id}/workspace/runs/{run_id}
Health
Identity
Max Code
- GETList App Store Categories
/v1/max-code/apps/categories - GETList Public Apps Catalog
/v1/max-code/apps/public - GETGet Public App Catalog Embed Endpoint
/v1/max-code/apps/public/{app_id}/embed - GETGet Public App Listing Versions
/v1/max-code/apps/public/{app_id}/versions - GETList Max Code Asset Packs
/v1/max-code/asset-packs - GETList Owner App Listings
/v1/max-code/listings - GETList Max Code Projects
/v1/max-code/projects - POSTCreate Max Code Project
/v1/max-code/projects - POSTClone Max Code Project
/v1/max-code/projects/clone - POSTImport Max Code Project
/v1/max-code/projects/import - DELETEDelete Max Code Project
/v1/max-code/projects/{project_id} - GETGet Max Code Project
/v1/max-code/projects/{project_id} - PATCHRename Max Code Project
/v1/max-code/projects/{project_id} - PUTSave Max Code Project
/v1/max-code/projects/{project_id} - GETList Max Code Project Assets
/v1/max-code/projects/{project_id}/assets - POSTCreate Max Code Project Asset
/v1/max-code/projects/{project_id}/assets - DELETEDelete Max Code Project Asset
/v1/max-code/projects/{project_id}/assets/{asset_key} - GETGet Max Code Project Asset
/v1/max-code/projects/{project_id}/assets/{asset_key} - GETGet Max Code Project Asset Content
/v1/max-code/projects/{project_id}/assets/{asset_key}/content - GETList Project App Listings
/v1/max-code/projects/{project_id}/listings - GETGet Project App State
/v1/max-code/projects/{project_id}/state - PATCHPatch Project App State
/v1/max-code/projects/{project_id}/state - DELETEDelete Project App State Key
/v1/max-code/projects/{project_id}/state/{state_key} - GETGet Project App State Key
/v1/max-code/projects/{project_id}/state/{state_key} - PUTPut Project App State Key
/v1/max-code/projects/{project_id}/state/{state_key} - GETList Max Code Project Versions
/v1/max-code/projects/{project_id}/versions - GETList Max Code Templates
/v1/max-code/templates
Max Code builds
- GETList Runs
/v1/max-code/projects/{project_id}/build-runs - POSTCreate Run
/v1/max-code/projects/{project_id}/build-runs - GETGet Run
/v1/max-code/projects/{project_id}/build-runs/{run_id} - POSTCancel Run
/v1/max-code/projects/{project_id}/build-runs/{run_id}/cancel - GETVerification Source
/v1/max-code/projects/{project_id}/build-runs/{run_id}/source
Max Code creation
- POSTCreate
/v1/max-code/creations - GETCapabilities
/v1/max-code/creations/capabilities - GETGet Creation
/v1/max-code/creations/{project_id} - GETStatus
/v1/max-code/creations/{project_id}/runs/{run_id} - GETPdf Text
/v1/max-code/creations/{project_id}/runs/{run_id}/exports/pdf/text - GETExport Bytes
/v1/max-code/creations/{project_id}/runs/{run_id}/exports/{format} - GETPreview Bytes
/v1/max-code/creations/{project_id}/runs/{run_id}/previews/{index}