---
title: Create K2 stream
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[K2](https://developers.cloudflare.com/api/go/resources/k2)

[Streams](https://developers.cloudflare.com/api/go/resources/k2/subresources/streams)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Create K2 stream

client.K2.Streams.New(ctx, params) (\*[StreamNewResponse](<https://developers.cloudflare.com/api/go/resources/k2#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)>), error)

POST/accounts/{account\_id}/k2/streams

Create a new K2 stream.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### ParametersExpand Collapse

<details>

<summary>

params StreamNewParams

</summary>

AccountID param.Field\[string]

Path param: Specifies the public ID of the account.

maxLength32

minLength32

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

<details>

<summary>

HTTP param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/k2/subresources/streams/methods/create#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)">StreamNewParamsHTTP</a>]

Body param

</summary>

<details>

<summary>

type StreamNewParamsHTTPEnabled struct{…}

</summary>

Enabled StreamNewParamsHTTPEnabledEnabled

Indicates whether the HTTP endpoint accepts records.

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%200%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%200">Link to this property</a>

<details>

<summary>

type StreamNewParamsHTTPObject struct{…}

</summary>

Enabled StreamNewParamsHTTPObjectEnabled

Indicates whether the HTTP endpoint accepts records.

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20enabled">Link to this property</a>

Authentication boolOptional

Indicates whether the HTTP endpoint requires an API token with K2 produce permission. When false or omitted, the endpoint accepts unauthenticated records.

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20authentication">Link to this property</a>

<details>

<summary>

CORS StreamNewParamsHTTPObjectCORSOptional

</summary>

<details>

<summary>

Origins StreamNewParamsHTTPObjectCORSOriginsUnionOptional

Allows requests from these HTTP or HTTPS origins. Use a wildcard only as the sole origin.

</summary>

One of the following:

type StreamNewParamsHTTPObjectCORSOriginsArray \[]StreamNewParamsHTTPObjectCORSOriginsArray

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins%20%3E%20(variant)%200">Link to this property</a>

type StreamNewParamsHTTPObjectCORSOriginsArray \[]string

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20cors">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http%20%3E%20(schema)%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20http">Link to this property</a>

Name param.Field\[string]

Body param: Specifies the name of the K2 stream.

maxLength128

minLength1

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20name">Link to this property</a>

RetentionSeconds param.Field\[int64]Optional

Body param: Sets the record retention period from 1 hour (3600 seconds) to 30 days (2592000 seconds), inclusive.

maximum2592000

minimum3600

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20retention_seconds">Link to this property</a>

<details>

<summary>

WorkerBinding param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/k2/subresources/streams/methods/create#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding%20%3E%20(schema)">StreamNewParamsWorkerBinding</a>]Optional

Body param

</summary>

<details>

<summary>

type StreamNewParamsWorkerBindingEnabled struct{…}

</summary>

Enabled StreamNewParamsWorkerBindingEnabledEnabled

Indicates whether Workers bindings can produce records to the stream.

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding%20%3E%20(schema)%20%3E%20(variant)%200%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding%20%3E%20(schema)%20%3E%20(variant)%200">Link to this property</a>

<details>

<summary>

type StreamNewParamsWorkerBindingEnabled struct{…}

</summary>

Enabled StreamNewParamsWorkerBindingEnabledEnabled

Indicates whether Workers bindings can produce records to the stream.

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding%20%3E%20(schema)%20%3E%20(variant)%201%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding%20%3E%20(schema)%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20worker_binding">Link to this property</a>

</details>

[Link to this property](<#(resource)%20k2.streams%20%3E%20(method)%20create%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type StreamNewResponse struct{…}

</summary>

ID string

Specifies the public ID of the K2 stream.

maxLength32

minLength32

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20id">Link to this property</a>

CreatedAt Time

formatdate-time

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20created_at">Link to this property</a>

Endpoint string

Indicates the base HTTP endpoint for producing and consuming records.

formaturi

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20endpoint">Link to this property</a>

<details>

<summary>

HTTP StreamNewResponseHTTP

</summary>

One of the following:

<details>

<summary>

type StreamNewResponseHTTPEnabled struct{…}

</summary>

Enabled StreamNewResponseHTTPEnabledEnabled

Indicates whether the HTTP endpoint accepts records.

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%200%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%200">Link to this property</a>

<details>

<summary>

type StreamNewResponseHTTPObject struct{…}

</summary>

Enabled StreamNewResponseHTTPObjectEnabled

Indicates whether the HTTP endpoint accepts records.

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20enabled">Link to this property</a>

Authentication boolOptional

Indicates whether the HTTP endpoint requires an API token with K2 produce permission. When false or omitted, the endpoint accepts unauthenticated records.

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20authentication">Link to this property</a>

<details>

<summary>

CORS StreamNewResponseHTTPObjectCORSOptional

</summary>

<details>

<summary>

Origins StreamNewResponseHTTPObjectCORSOriginsUnionOptional

Allows requests from these HTTP or HTTPS origins. Use a wildcard only as the sole origin.

</summary>

One of the following:

type StreamNewResponseHTTPObjectCORSOriginsArray \[]StreamNewResponseHTTPObjectCORSOriginsArrayItem

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins%20%3E%20(variant)%200">Link to this property</a>

type StreamNewResponseHTTPObjectCORSOriginsArray \[]string

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20cors%20%3E%20(property)%20origins">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201%20%3E%20(property)%20cors">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20http">Link to this property</a>

ModifiedAt Time

formatdate-time

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20modified_at">Link to this property</a>

Name string

Indicates the name of the K2 stream.

maxLength128

minLength1

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20name">Link to this property</a>

RetentionSeconds int64

Shows the configured record retention period from 1 hour (3600 seconds) to 30 days (2592000 seconds), inclusive.

maximum2592000

minimum3600

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20retention_seconds">Link to this property</a>

<details>

<summary>

WorkerBinding StreamNewResponseWorkerBinding

</summary>

One of the following:

<details>

<summary>

type StreamNewResponseWorkerBindingEnabled struct{…}

</summary>

Enabled StreamNewResponseWorkerBindingEnabledEnabled

Indicates whether Workers bindings can produce records to the stream.

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20worker_binding%20%3E%20(variant)%200%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20worker_binding%20%3E%20(variant)%200">Link to this property</a>

<details>

<summary>

type StreamNewResponseWorkerBindingEnabled struct{…}

</summary>

Enabled StreamNewResponseWorkerBindingEnabledEnabled

Indicates whether Workers bindings can produce records to the stream.

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20worker_binding%20%3E%20(variant)%201%20%3E%20(property)%20enabled">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20worker_binding%20%3E%20(variant)%201">Link to this property</a>

</details>

<a href="#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)%20%3E%20(property)%20worker_binding">Link to this property</a>

</details>

[Link to this property](<#(resource)%20k2.streams%20%3E%20(model)%20StreamNewResponse%20%3E%20(schema)>)

### Create K2 stream

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/k2"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  stream, err := client.K2.Streams.New(context.TODO(), k2.StreamNewParams{
    AccountID: cloudflare.F("0123105f4ecef8ad9ca31a8372d0c353"),
    HTTP: cloudflare.F[k2.StreamNewParamsHTTPUnion](k2.StreamNewParamsHTTPEnabled{
      Enabled: cloudflare.F(k2.StreamNewParamsHTTPEnabledEnabledFalse),
    }),
    Name: cloudflare.F("my_k2_stream"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", stream.ID)
}
```

200 example

```
{
  "result": {
    "id": "053e105f4ecef8ad9ca31a8372d0c353",
    "created_at": "2019-12-27T18:11:19.117Z",
    "endpoint": "https://053e105f4ecef8ad9ca31a8372d0c353.k2.cloudflarestorage.com",
    "http": {
      "enabled": false
    },
    "modified_at": "2019-12-27T18:11:19.117Z",
    "name": "my_k2_stream",
    "retention_seconds": 604800,
    "worker_binding": {
      "enabled": false
    }
  },
  "success": true
}
```

##### Returns Examples

200 example

```
{
  "result": {
    "id": "053e105f4ecef8ad9ca31a8372d0c353",
    "created_at": "2019-12-27T18:11:19.117Z",
    "endpoint": "https://053e105f4ecef8ad9ca31a8372d0c353.k2.cloudflarestorage.com",
    "http": {
      "enabled": false
    },
    "modified_at": "2019-12-27T18:11:19.117Z",
    "name": "my_k2_stream",
    "retention_seconds": 604800,
    "worker_binding": {
      "enabled": false
    }
  },
  "success": true
}
```