App & Machine Management¶
Low-level Fly.io app and machine lifecycle operations.
ensure_app
async
¶
Ensure a Fly.io app exists, creating it if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str | None
|
Name for the Fly app. Defaults to |
None
|
org
|
str
|
Fly.io organization slug. Defaults to |
DEFAULT_ORG
|
region
|
str
|
Preferred Fly.io region for machines created under this app.
Defaults to |
DEFAULT_REGION
|
token
|
str | None
|
Optional explicit API token (otherwise reads FLY_API_TOKEN). |
None
|
Returns:
| Type | Description |
|---|---|
FlyApp
|
A FlyApp dataclass with the app name, org, and preferred region. |
Source code in flaude/app.py
create_app
async
¶
Create a new Fly.io app with configurable name, org, and region.
The region is stored in the returned :class:FlyApp as the preferred
region for machines created under this app. Fly.io assigns machines to
regions at machine-creation time, not at app-creation time, so this value
is used as a convenient default rather than sent to the app-creation API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Unique name for the new Fly.io application. |
required |
org
|
str
|
Fly.io organization slug that will own the app.
Defaults to |
DEFAULT_ORG
|
region
|
str
|
Preferred Fly.io region for machines in this app
(e.g. |
DEFAULT_REGION
|
token
|
str | None
|
Optional explicit API token (otherwise reads |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FlyApp
|
class: |
Raises:
| Type | Description |
|---|---|
FlyAPIError
|
If the API call fails (e.g. name taken, auth error). |
Source code in flaude/app.py
get_app
async
¶
Return a FlyApp if it already exists, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly.io application name to look up. |
required |
token
|
str | None
|
Optional explicit API token (otherwise reads |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FlyApp | None
|
class: |
FlyApp | None
|
is not found (HTTP 404). |
Raises:
| Type | Description |
|---|---|
FlyAPIError
|
If the API returns any error other than 404. |
Source code in flaude/app.py
FlyApp
dataclass
¶
Represents a Fly.io application used by flaude.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The Fly.io application name. |
org |
str
|
The Fly.io organization slug that owns the app. |
region |
str
|
The preferred region for machines created under this app. Stored locally; not a Fly.io API-level concept for apps. |
create_machine
async
¶
Create a Fly.io machine and return its ID/status.
Sends a POST to /v1/apps/{app}/machines with the payload built from
config. The Fly API returns the machine details synchronously once the
machine has been accepted (not necessarily started).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app to create the machine under. |
required |
config
|
MachineConfig
|
A :class: |
required |
name
|
str | None
|
Optional human-readable name for the machine. |
None
|
token
|
str | None
|
Explicit API token (falls back to |
None
|
timeout
|
float
|
HTTP request timeout in seconds. |
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FlyMachine
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required config fields are missing. |
FlyAPIError
|
If the Fly API returns an error. |
Source code in flaude/machine.py
get_machine
async
¶
Fetch the current state of a machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app the machine belongs to. |
required |
machine_id
|
str
|
The machine ID. |
required |
token
|
str | None
|
Explicit API token. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FlyMachine
|
class: |
Source code in flaude/machine.py
stop_machine
async
¶
Send a stop signal to a machine.
This is a best-effort call — if the machine is already stopped or destroyed the error is suppressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app the machine belongs to. |
required |
machine_id
|
str
|
The machine ID to stop. |
required |
token
|
str | None
|
Explicit API token (falls back to |
None
|
Source code in flaude/machine.py
destroy_machine
async
¶
Destroy a machine, removing it permanently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app the machine belongs to. |
required |
machine_id
|
str
|
The machine ID to destroy. |
required |
force
|
bool
|
If True, force-destroy even if the machine is running. |
True
|
token
|
str | None
|
Explicit API token. |
None
|
Source code in flaude/machine.py
start_machine
async
¶
Start a stopped machine.
Best-effort — if the machine is already started or gone, the error is suppressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app the machine belongs to. |
required |
machine_id
|
str
|
The machine ID to start. |
required |
token
|
str | None
|
Explicit API token (falls back to |
None
|
Source code in flaude/machine.py
update_machine
async
¶
Update a stopped machine's configuration.
Sends a PUT to /v1/apps/{app}/machines/{id} with the full config
payload. Used to inject new env vars (prompt, session ID) between
session turns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app the machine belongs to. |
required |
machine_id
|
str
|
The machine ID to update. |
required |
config
|
MachineConfig
|
Updated :class: |
required |
name
|
str | None
|
Optional machine name override. |
None
|
token
|
str | None
|
Explicit API token. |
None
|
timeout
|
float
|
HTTP request timeout in seconds. |
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FlyMachine
|
class: |
Source code in flaude/machine.py
FlyMachine
dataclass
¶
Represents a running (or recently created) Fly.io machine.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The unique Fly machine ID assigned by the Fly Machines API. |
name |
str
|
Human-readable name for the machine (may be empty). |
state |
str
|
Current machine state (e.g. |
region |
str
|
The Fly.io region the machine is running in (e.g. |
instance_id |
str
|
Internal instance identifier assigned by Fly.io. |
app_name |
str
|
The Fly.io application this machine belongs to. |
cleanup
async
¶
Stop and destroy this machine, handling all edge cases gracefully.
This method first attempts to stop the machine, then destroys it. Both steps tolerate already-stopped and already-destroyed states, ensuring no orphaned resources remain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | None
|
Explicit API token (falls back to |
None
|