# MD_CREATE_FLIGHT
> Create a new Flight in your MotherDuck account.
Creates a new [Flight](/concepts/flights) and returns its summary. The initial version is captured from `source_code`, `requirements_txt`, `config`, `access_token_name`, and `flight_secret_names`.

You are responsible for the code you run and the packages it installs. Flights does not scan customer code or dependencies. Avoid untrusted packages, pin dependency versions, and treat dependency installs as a supply-chain risk.

## Syntax

```sql
SELECT * FROM MD_CREATE_FLIGHT(
    name := 'my_flight',
    source_code := '<python_source>',
    schedule_cron := '0 * * * *',
    requirements_txt := 'duckdb==1.5.3',
    config := MAP {'KEY': 'value'},
    access_token_name := '<token_name>',
    flight_secret_names := ['secret_name']
);
```

## Parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `name` | `VARCHAR` | Yes | Human-readable Flight name. Must be non-empty. |
| `access_token_name` | `VARCHAR` | No | Label of a MotherDuck access token to run the Flight as. The token value is injected into the Flight as `MOTHERDUCK_TOKEN`. Omit it to use the default `MotherDuck Flights` access token for your user. List labels with `SELECT * FROM md_access_tokens();`. |
| `source_code` | `VARCHAR` | Yes | Python source for the Flight. A single-file program, executed as a plain script; end it with `if __name__ == "__main__": main()` to invoke your entrypoint. |
| `schedule_cron` | `VARCHAR` | No | 5-field cron expression in UTC. Omit for an on-demand-only Flight. |
| `requirements_txt` | `VARCHAR` | No | Contents of a `requirements.txt`, one pinned package per line. |
| `config` | `MAP(VARCHAR, VARCHAR)` | No | Non-secret key/value pairs surfaced to the Flight as environment variables. |
| `flight_secret_names` | `LIST(VARCHAR)` | No | List of names of [Flight secrets](/sql-reference/motherduck-sql-reference/create-secret#flight-secrets) (`TYPE FLIGHTS`). Each key in a secret's `PARAMS` map is surfaced to the Flight as an environment variable. |

:::note
`source_code` is capped at 200 KB and `requirements_txt` at 20 KB. Load large reference data from object storage at run time instead of embedding it in the source.
:::

## Return columns

| Column | Type | Description |
|---|---|---|
| `flight_id` | `UUID` | Unique identifier of the created Flight. |
| `flight_name` | `VARCHAR` | The Flight name. |
| `schedule_cron` | `VARCHAR` | The cron expression, or `NULL` for on-demand. |
| `status` | `VARCHAR` | Schedule status (for example, `JOB_STATUS_ACTIVE`). |
| `current_version` | `INTEGER` | Always `1` for a newly created Flight. |
| `created_at` | `TIMESTAMP WITH TIME ZONE` | Creation timestamp. |
| `updated_at` | `TIMESTAMP WITH TIME ZONE` | Last update timestamp. |

## Examples

Minimal Flight, no schedule:

```sql
SELECT flight_id
FROM MD_CREATE_FLIGHT(
    name := 'heartbeat',
    source_code := 'def main(): print("hello")

if __name__ == "__main__":
    main()'
);
```

Scheduled Flight with config, running as a specific access token:

```sql
SELECT flight_id, current_version
FROM MD_CREATE_FLIGHT(
    name := 'hourly_metrics',
    access_token_name := 'analytics_token',
    source_code := $$
import duckdb

def main():
    con = duckdb.connect("md:")
    con.execute("INSERT INTO analytics.hourly_counts SELECT now(), COUNT(*) FROM events")

if __name__ == "__main__":
    main()
$$,
    requirements_txt := 'duckdb==1.5.3',
    schedule_cron := '0 * * * *',
    config := MAP {'REGION': 'eu-central-1'}
);
```

## Related

- [`MD_UPDATE_FLIGHT`](../md-update-flight) — Modify a Flight's content or metadata.
- [`MD_RUN_FLIGHT`](../md-run-flight) — Trigger an on-demand run.
- [`MD_DELETE_FLIGHT`](../md-delete-flight) — Delete a Flight.
- [`create_flight` MCP tool](/sql-reference/mcp/) — AI-agent equivalent.


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `POST https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

Payload:

```json
{
  "page_path": "/sql-reference/motherduck-sql-reference/flights/md-create-flight/",
  "page_title": "MD_CREATE_FLIGHT",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed payloads, and `429` when rate-limited.
