New · Agents · API
How to deploy an AI agent as an API, with the inputs and outputs you choose
An AI agent that did the job once in a chat is not yet something your app can call. To deploy an AI agent as an API, you need a version that repeats the steps that worked, named inputs for each call and a result your code can read. As of today, Save version on FlyMy.AI asks for exactly that: what the project takes in and what it gives back, drafted from the chat that worked. The saved version then runs from your code, a webhook or a schedule, and people you share the project with see the API their own copy will have. This guide walks through each step, with requests to paste into your assistant and the code that calls the result.
What it means to deploy an AI agent as an API
To deploy an AI agent as an API takes three things: a fixed version of what the agent does, a contract that says which inputs a call sends and which fields the result has, and an address your code can call. A chat has none of them. The agent plans as it goes, the inputs are buried in what you typed, and the result is whatever it said last.
On FlyMy.AI you deploy a project: an app, a page or a fleet, with a master agent that talks to you and helper agents it hands work to. The project's version is its master's saved version (a compilation, in the API): the steps of a run that worked, written down so they run again with new values. FlyMy.AI hosts it, so AI agent deployment needs no server of yours, and every way to start it, from code, from a webhook or on a schedule, runs that same version.
The contract is two JSON Schema objects. input_schema lists what goes in, the parameters of a call. output_schema lists what comes out, the fields of the result. They turn "the task from my chat" into a call with parameters, and they are what your code, a webhook and a schedule fill in.
Why a saved version needs inputs and outputs
Saving a version compiles a chat: a compiler reads what the agent did and writes the steps down. To do that well, it has to know which parts of the chat were the job and which were the details of this one time. In a transcript, a video link, two photos and a sentence about who becomes whom look just like a setting the agent should keep forever.
Without inputs and outputs the compiler has nothing to build the version around. Until this release, Save version did not ask, so a project could reach the end of a good chat and still have no version for anything to call. Now the question comes first, and nothing starts until it has an answer: a draft from the chat, your own fields, or a clear "none".
A real case: Genjutsu Studio, a character swap AI agent, as an API
Genjutsu Studio is a FlyMy.AI project that swaps the people in a short video for characters from photos: people, pets, mascots or products. The moves, the camera and the timing stay; only the characters change. It is also a public template, Genjutsu Studio, that you can clone, and our AI agent templates post shows a full test run.
A Genjutsu Studio project in the app had done the job in its master's chat, yet its master's version could not be saved: the compiler had no inputs and outputs. With the new dialog, the draft made from its chat named exactly these inputs:
| Input | What it is | Rule |
|---|---|---|
video_url | The link to the video to change | Required |
reference_photos | Links to the photos of the new characters, in order: photo 1, photo 2 | Required, 1 to 4 |
character_mapping | Who becomes whom, in plain words | Required |
duration_seconds | How many seconds from the start to use | 4 to 15, 5 by default |
resolution | The quality of the result | 480p or 720p, 480p by default |
The outputs were the final video (final_video_url), the depth video (depth_video_url), the prompt, the settings and the cost. The draft follows what that chat did; the current template also offers 1080p.
We accepted the draft as it was and added one line on what to keep fixed and what varies: keep the photo checks, the trim, the depth video, the generation and the original sound; let the video, the photos, the mapping, the seconds and the resolution change. The version compiled. Then a call from code with new values, the two photos in swapped order, 4 seconds and 480p, started that version with no chat and nobody at the keyboard, and the run took every input from the call.
How to deploy an AI agent as an API in five steps
The steps in the FlyMy.AI app, at app.flymy.ai/projects. The next section does the same from Claude, ChatGPT or Codex.
1. Get one good run in the master's chat
Open the project and give its master the task with real inputs: a link, a file, a few settings. Refine it in the same chat until the result is right. That run is what the version will repeat, so the draft of the inputs and outputs comes from it too.
Run my video project once on the video and the two photos I attach: the dancer on the left becomes photo 1, the one on the right photo 2.
2. Press Save version in Run it
In the project workspace, open Run it and press Save version. If the project has never named its inputs and outputs, nothing is saved yet: an Inputs and outputs card appears in the master's chat instead, and it asks before the version is saved.
3. Answer Inputs and outputs
The card has two sides, What goes in and What comes out. Each offers Suggested from this chat, a draft read from the conversation, and Write my own; the input side adds No inputs and the output side Free-form result. A field has a name, a type (Text, Number, Whole number, Yes or no, Link, List of links, List or Object) and a few words on what it is.
- What to keep fixed and what varies tells the compiler which parts of the run stay the same and which change with the inputs.
- JSON shows the two schemas you are about to save.
- A file goes in as a public link: a string with
"format": "uri".
4. Save the helpers and the master
Press Save version on the card. FlyMy.AI saves the helpers the master used first, then the master, and says in the chat what it saved. If a helper still needs one trial run by the master, the save names it and stops before the master: let the master run that helper once, then save again.
5. Call it
Run it now shows the inputs and outputs and offers Change inputs and outputs, which asks again; a new answer makes a new version. For developers shows the call with your agent's id, On an event gives the project a webhook, and Schedule asks for the values of the required inputs.
Deploy an AI agent from Claude, ChatGPT or Codex
The same dialog works from any assistant connected to the FlyMy.AI Agents MCP, https://mcp-agents.flymy.ai/mcp. Add it once and sign in; the sign-in creates an account if you have none.
- Claude Code:
claude mcp add --scope user --transport http flymyai https://mcp-agents.flymy.ai/mcp, then/mcpto sign in. - Codex:
codex mcp add flymyai --url https://mcp-agents.flymy.ai/mcpopens the sign-in. - claude.ai, Claude Desktop and ChatGPT: add the same URL as a custom connector.
Then ask for the save in plain words. The tools follow the steps above:
projects_savesaves the project, helpers first and then the master. If the project has never named its inputs and outputs, it answers400 contract_requiredwithmissing,currentandsuggestions, and nothing starts.suggest_schemawith the master's chat asexecution_idandsave: falsedrafts both schemas from that conversation without storing them.- The assistant shows you the draft, you confirm or change it, and it calls
projects_saveagain withinput_schemaandoutput_schema(nullmeans none) and a newoperation_key. projects_save_statusfollows the save until it is done.
Save a version of my video project and ask me what it should take in and return.
Draft the inputs and outputs of my video project from its master's chat, show them to me, and save the version once I confirm.
Save my video project with a video link and two photo links as inputs, then show me the call to run it from code.
A good assistant never invents the schema: the tools ask it to show you the draft and save only what you confirm. Over REST the same steps are:
| Step | Agents MCP | REST, under /api/v1/agents |
|---|---|---|
| Save a version | projects_save with an operation_key | POST /projects/<id>/save/ with an Idempotency-Key and ask_contract: true |
| Draft from the chat | suggest_schema with execution_id and save: false | POST /executions/<chat>/suggest-schema/ with save: false |
| Follow the save | projects_save_status | GET /projects/<id>/save/ |
With ask_contract: true, a save without an answer is refused before anything runs (shortened):
{
"code": "contract_required",
"message": "Say what the project takes in and gives back before it is saved: ...",
"missing": ["input_schema", "output_schema"],
"current": { ... },
"suggestions": { "input_schema": [ ... ], "output_schema": [ ... ] }
}
Each suggestion is a variant with a label, a schema and a text, to accept or edit. Send the answer with a new key, and add input_description, output_description and guidance in words if you like. A project that answered "none" once is not asked again.
curl -X POST \
"https://backend.flymy.ai/api/v1/agents/projects/<project id>/save/" \
-H "X-API-KEY: $FLYMYAI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"ask_contract": true,
"input_schema": {
"type": "object",
"properties": {
"video_url": {"type": "string", "format": "uri"},
"reference_photos": {
"type": "array", "minItems": 1, "maxItems": 4,
"items": {"type": "string", "format": "uri"}
},
"character_mapping": {"type": "string"}
},
"required": ["video_url", "reference_photos", "character_mapping"]
},
"output_schema": null,
"guidance": "Keep every step of the run; the inputs change."
}'
The answer is the save, 202 while it runs: its status (running, done or failed), its step (plan, subagents or master), the helpers it saved or kept, and the master version once it is ready.
Call your AI agent API from code
Once the version is saved, For developers in Run it shows the call with your agent's id. Your API key is on your Developers page in the app; keep it in an environment variable on your server, never in a browser or a shared repository. A call starts a run of the live version and answers at once with the run's id; your code then reads the run's status until it is settled and takes the result.
With cURL:
curl -X POST \
"https://backend.flymy.ai/api/v1/agents/compilations/live/<agent id>/run-instruction/" \
-H "X-API-KEY: $FLYMYAI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"variables": {
"video_url": "https://example.com/dance.mp4",
"reference_photos": ["https://example.com/photo-1.jpg",
"https://example.com/photo-2.jpg"],
"character_mapping": "Left dancer becomes photo 1, right dancer photo 2.",
"duration_seconds": 5,
"resolution": "480p"
}}'
# Then read the run until is_settled is true; a completed run has result
curl -H "X-API-KEY: $FLYMYAI_API_KEY" \
"https://backend.flymy.ai/api/v1/agents/executions/<run id>/status/"
With Python:
import os, time, uuid
import requests
API = "https://backend.flymy.ai/api/v1/agents"
KEY = {"X-API-KEY": os.environ["FLYMYAI_API_KEY"]}
AGENT = "<agent id>" # For developers in Run it shows it
run = requests.post(
f"{API}/compilations/live/{AGENT}/run-instruction/",
headers={**KEY, "Idempotency-Key": str(uuid.uuid4())}, # one key per run
json={"variables": {
"video_url": "https://example.com/dance.mp4",
"reference_photos": ["https://example.com/photo-1.jpg",
"https://example.com/photo-2.jpg"],
"character_mapping": "Left dancer becomes photo 1, right dancer photo 2.",
"duration_seconds": 5,
"resolution": "480p",
}},
timeout=30,
)
run.raise_for_status() # 400 when the variables do not match the input schema
run_id = run.json()["id"]
while True:
status = requests.get(f"{API}/executions/{run_id}/status/",
headers=KEY, timeout=30).json()
if status["is_settled"]:
break
time.sleep(5)
if status["status"] != "completed":
raise SystemExit(f"run {run_id}: {status['status']} {status.get('error')}")
print(status["result"]) # final_video_url, depth_video_url, ...
With JavaScript:
// Node.js 20+ (.mjs)
const API = "https://backend.flymy.ai/api/v1/agents";
const headers = { "X-API-KEY": process.env.FLYMYAI_API_KEY };
const AGENT = "<agent id>"; // For developers in Run it shows it
const run = await fetch(`${API}/compilations/live/${AGENT}/run-instruction/`, {
method: "POST",
headers: {
...headers,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(), // one key per run
},
body: JSON.stringify({
variables: {
video_url: "https://example.com/dance.mp4",
reference_photos: [
"https://example.com/photo-1.jpg",
"https://example.com/photo-2.jpg",
],
character_mapping: "Left dancer becomes photo 1, right dancer photo 2.",
duration_seconds: 5,
resolution: "480p",
},
}),
}).then((response) => response.json());
let status;
do {
await new Promise((resolve) => setTimeout(resolve, 5000));
status = await fetch(`${API}/executions/${run.id}/status/`, { headers })
.then((response) => response.json());
} while (!status.is_settled);
console.log(status.status, status.result);
- One
Idempotency-Keyper run. A retry with the same key after a lost answer returns the same run instead of starting a second one. - Inputs are checked before anything runs. Leave out a required input or send the wrong type, and the call is refused with
400and a message that says what failed. - One address for every version. A new version or a rollback changes what the call runs, not the address or the key.
For the whole platform side of calling agents from your product, with the sandbox, the tools and what a run costs, see Build, deploy and call AI agents via API.
Run the same version on a webhook or a schedule
A saved version is not only for your code. In Run it, On an event gives the project a webhook, and the event sends the inputs, so another service can start the same version. Schedule runs it on a cron and asks for the values of the required inputs once; every scheduled run uses them. All three run the live version, so when you save a new one, they run the new one.
Put my saved project on a schedule every Monday at 9:00 and ask me for the values of its required inputs.
Agent as a service: share the project, others call their own copy
Agent as a service means an AI agent other people use without building it. On FlyMy.AI that is a shared project. In the project workspace choose Share, then Make public & copy link, or ask your assistant, which calls projects_share. The project's one link, https://app.flymy.ai/projects/<project id>, then opens for anyone who has it.
A visitor first sees a card about the project: who made it, its version, how many times it was copied, what it does, its agents and the tools they use, what a copy gets, a Clone button and Clone from your AI agent for assistants. When the project has a saved version with its inputs and outputs, the page goes on, after an "or", with an API card titled Someone made this an API for you. It lists the inputs and the outputs and shows the call in Python, cURL and JavaScript. After Clone, For developers in the visitor's copy shows the same call with the copy's own id.
The copy runs on the visitor's own account and balance. It brings the instructions, the saved version and the files, with schedules switched off; the author's chats, data and keys never come along. An assistant reads the same API from projects_get, as api: the version, the inputs and the outputs.
The link shows the agents' chats and files, read only, so keep secrets and personal data out of them. Make private stops new views and copies at once; copies already made belong to the people who made them.
Open the shared FlyMy.AI project at the link I paste, clone it, and show me the call to run its saved version from my copy.
FAQ
How do I deploy an AI agent?
Run the task once in the agent's chat until the result is right, then save that run as a version with named inputs and outputs. On FlyMy.AI that is Save version in a project's Run it: it asks what each run takes in and gives back, saves the helpers and then the master, and the version runs from your code, a webhook or a schedule. FlyMy.AI hosts the agent, so taking it to production needs no AI agent hosting or server of your own.
What is an AI agent API?
An HTTPS endpoint that runs an agent with named inputs and returns its result in a known shape. On FlyMy.AI the inputs and the result are JSON Schema objects saved with the version, and the call is POST /api/v1/agents/compilations/live/<agent id>/run-instruction/ with variables and an Idempotency-Key.
How do I add an AI agent to my existing SaaS product?
Build the agent as a FlyMy.AI project, save a version with the inputs your product will send, and call it from your backend with your API key. Your product sends the variables, reads the run's status and shows the result; the key stays on your server, never in the browser. When each of your users connects their own accounts, call a deployment with their external_user_id instead.
How do I run an AI agent on a schedule or cron?
Save a version first: a schedule runs the saved version, not the chat. In Run it, choose Schedule, set when it runs and give the values of the required inputs once; every scheduled run uses them. When you save a new version, the schedule runs the new one.
What is agent as a service?
An AI agent that other people or programs use without building it themselves. On FlyMy.AI you share a project by link: visitors see what it does and, when its saved version has inputs and outputs, its API. They clone it and call their own copy on their own account and balance.
How do I orchestrate AI agents?
Give one agent the whole job and let it hand parts of it to helper agents. In a FlyMy.AI project the master agent talks to you and starts helpers for the work; Save version saves the helpers first and then the master, so the whole multi-agent project runs as one version behind one API.
Can I deploy an AI agent as an API with Python?
Yes. Save the version in the app or from your assistant, then call it with any HTTP client: the Python example above starts a run with requests and reads its result from the run's status. The same call works from cURL, JavaScript or any language that can send an HTTPS request.
Your agent worked once. Now call it from anywhere.
Save a version with its inputs and outputs, and run it from your code, a webhook or a schedule.