> For the complete documentation index, see [llms.txt](https://velora-1.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://velora-1.gitbook.io/docs/instruction-reference/create-stream.md). Agents can also search and read this documentation through its [MCP server](https://velora-1.gitbook.io/docs/~gitbook/mcp).

# create\_stream

Creates a new stream: initializes the `StreamConfig` PDA, initializes the vault token account, and transfers `total_amount` from the creator into the vault.

```rust
pub fn create_stream(ctx: Context<CreateStream>, params: CreateStreamParams) -> Result<()>
```

## Parameters (`CreateStreamParams`)

| Field                   | Type              | Notes                                                                                                       |
| ----------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------- |
| `stream_id`             | `u64`             | Caller-chosen id; unique per (creator, recipient) pair. Part of the PDA seed.                               |
| `total_amount`          | `u64`             | Token base units to lock. Must be `> 0`.                                                                    |
| `start_timestamp`       | `i64`             | Unix seconds. Linear unlock begins here.                                                                    |
| `end_timestamp`         | `i64`             | Unix seconds. Must be `> start_timestamp`.                                                                  |
| `cliff_timestamp`       | `i64`             | Required for `Cliff` / `CliffLinear`; must be strictly between start and end. Ignored otherwise (pass `0`). |
| `cliff_amount`          | `u64`             | `CliffLinear` only: lump sum unlocked at the cliff. Must be `<= total_amount`.                              |
| `schedule_type`         | `ScheduleType`    | `Linear` / `Cliff` / `CliffLinear` / `Milestone`.                                                           |
| `authority_type`        | `AuthorityType`   | `None` / `SingleKey` / `MultiSig` — who can call `release_milestone`.                                       |
| `release_authority`     | `Option<Pubkey>`  | Extra key allowed to release a milestone when `SingleKey`. `None` → defaults to the zero pubkey.            |
| `milestone_description` | `[u8; 128]`       | Free-form label; pad to 128 bytes (pass `Array(128).fill(0)` if unused).                                    |
| `is_cancellable`        | `bool`            | Master switch for `cancel`.                                                                                 |
| `cancel_authority`      | `CancelAuthority` | `CreatorOnly` / `Either` / `Neither`.                                                                       |

## Accounts

| Account                 | Signer | Mut | Notes                                                                  |
| ----------------------- | ------ | :-: | ---------------------------------------------------------------------- |
| `creator`               | ✅      |  ✅  | Pays rent for both new accounts; source of funds.                      |
| `recipient`             |        |     | Any pubkey. Must differ from `creator`.                                |
| `mint`                  |        |     | SPL mint of the streamed token.                                        |
| `stream_config`         |        |  ✅  | `init`, PDA `["stream", creator, recipient, stream_id]`.               |
| `vault`                 |        |  ✅  | `init`, PDA `["vault", stream_config]`, token account owned by itself. |
| `creator_token_account` |        |  ✅  | Must be owned by `creator` and match `mint`.                           |
| `token_program`         |        |     | SPL Token program.                                                     |
| `system_program`        |        |     |                                                                        |
| `rent`                  |        |     | Rent sysvar.                                                           |

## Behavior

1. Validate: `total_amount > 0`, `end > start`, `recipient != creator`.
2. For `Cliff` / `CliffLinear`: require `start < cliff_timestamp < end`.
3. For `CliffLinear`: require `cliff_amount <= total_amount`.
4. Populate `StreamConfig`, set `status = Active`, `amount_claimed = 0`.
5. Transfer `total_amount` from `creator_token_account` into the `vault`.

## Errors

| Code                   | Cause                                                       |
| ---------------------- | ----------------------------------------------------------- |
| `ZeroAmount`           | `total_amount == 0`                                         |
| `InvalidSchedule`      | `end <= start`, or cliff not strictly between start and end |
| `SameRecipientCreator` | `recipient == creator`                                      |
| `InvalidCliffAmount`   | `CliffLinear` with `cliff_amount > total_amount`            |
| `InvalidMint`          | `creator_token_account.mint != mint`                        |
| `Unauthorized`         | `creator_token_account.owner != creator`                    |

## Example (TypeScript / Anchor)

```ts
const streamId = new anchor.BN(1);

const streamConfig = anchor.web3.PublicKey.findProgramAddressSync(
  [
    Buffer.from("stream"),
    creator.publicKey.toBuffer(),
    recipient.publicKey.toBuffer(),
    streamId.toArrayLike(Buffer, "le", 8),
  ],
  program.programId
)[0];

const vault = anchor.web3.PublicKey.findProgramAddressSync(
  [Buffer.from("vault"), streamConfig.toBuffer()],
  program.programId
)[0];

const now = Math.floor(Date.now() / 1000);

await program.methods
  .createStream({
    streamId,
    totalAmount: new anchor.BN(1_000),
    startTimestamp: new anchor.BN(now),
    endTimestamp: new anchor.BN(now + 1_000),
    cliffTimestamp: new anchor.BN(0),
    cliffAmount: new anchor.BN(0),
    scheduleType: { linear: {} },
    authorityType: { none: {} },
    releaseAuthority: null,
    milestoneDescription: Array(128).fill(0),
    isCancellable: false,
    cancelAuthority: { creatorOnly: {} },
  })
  .accounts({
    creator: creator.publicKey,
    recipient: recipient.publicKey,
    mint,
    streamConfig,
    vault,
    creatorTokenAccount,
    tokenProgram: TOKEN_PROGRAM_ID,
    systemProgram: anchor.web3.SystemProgram.programId,
    rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  })
  .signers([creator])
  .rpc();
```

See the full end-to-end flow in the [Integration Guide](https://velora-1.gitbook.io/docs/guides/integration.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://velora-1.gitbook.io/docs/instruction-reference/create-stream.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
