# 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`.

## Syntax

```sql
SELECT * FROM MD_CREATE_FLIGHT(
    name := 'my_flight',
    access_token_name := '<token_name>',
    source_code := '<python_source>',
    schedule_cron := '0 * * * *',
    requirements_txt := 'duckdb==1.5.2',
    config := MAP {'KEY': 'value'},
    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` | Yes | Label of a MotherDuck access token. The token value is injected into the Flight as `MOTHERDUCK_TOKEN`. List labels with `SELECT * FROM md_access_tokens();`. |
| `source_code` | `VARCHAR` | Yes | Python source for the Flight. A single-file program with a top-level `def main(): ...`. |
| `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 MotherDuck-stored secret names. End-to-end secret delivery is still in development. |

## 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',
    access_token_name := 'analytics_token',
    source_code := 'def main(): print("hello")'
);
```

Scheduled Flight with config:

```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")
$$,
    requirements_txt := 'duckdb==1.5.2',
    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.
