> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Stream cohort

POST https://apps.sarvam.ai/api/scheduling/v1/orgs/{org_id}/workspaces/{workspace_id}/campaigns/{campaign_id}/cohorts/stream
Content-Type: application/json

Stream a cohort as JSON with two fields:

- `name` - Cohort name (1-50 characters)
- `users` - Array of user records (1-1000)

**When to use**

Stream cohort adds contacts to a campaign programmatically (up to 1000 users per request). Use it when your system already has user records and you do not need to upload a CSV.

- **CRM integration** - sync leads or customers from Salesforce, HubSpot, Zoho, or your own database into a campaign
- **Webhooks and automation** - push contacts from form submissions, payment events, or internal workflows
- **Active campaigns** - queue new contacts to dial within the current schedule (same as Add cohort in the dashboard)
- **Scheduled or paused campaigns** - load contacts before the campaign starts, or while it is paused
- **Incremental batches** - send multiple API calls over time instead of one large CSV upload

For CSV files, use **Upload cohort** instead.

The campaign must be **active**, **scheduled**, or **paused**. Processing is asynchronous - poll **Get cohort** until `status` is `completed` or `failed`.

**Limits and rules:**
- `user_phone_number` is required for every user (E.164 preferred; 10-digit Indian numbers are normalized automatically)
- `app_variables` must match variables configured on the agent
- `app_overrides` supports only: `initial_language_name`, `initial_state_name`, `initial_bot_message`

**Common validation errors:**
- No users, or more than 1000 users
- Invalid cohort name
- Missing `user_phone_number`
- Unsupported `app_overrides` key
- Unknown `app_variables` for the selected agent.

Reference: https://docs.sarvam.ai/api-reference/campaigns/cohorts/stream

## Request

### Path parameters

- `org_id` (string, required)
- `workspace_id` (string, required)
- `campaign_id` (string, required)

### Body (application/json)

- `name` (string, required) — Cohort name (1-50 characters). Letters, numbers, spaces, underscores, and hyphens only.
- `users` (list of object, required) — List of user records (1-1000).
  - `user_phone_number` (string, required) — Phone number in E.164 format (for example `+919876543210`). 10-digit Indian numbers are also accepted and normalized automatically.
  - `user_identifier` (string, optional, nullable) — Optional customer or user ID.
  - `app_variables` (map from string to string, optional) — Key-value strings for agent variables. Keys must match variables configured on the agent.
  - `app_overrides` (map from string to string, optional) — Per-user overrides. Supported keys: `initial_language_name`, `initial_state_name`, `initial_bot_message`.

## Response

### 200

Successful Response

- `name` (string, required) — Name of the resource
- `cohort_id` (string, required) — Unique identifier for the cohort
- `status` (enum, required) — Current status
  - Allowed values: `processing`, `completed`, `failed`
- `source_type` (enum, required) — How the cohort was uploaded
  - Allowed values: `pre_signed_url`, `file_upload`
- `created_by` (string, required) — User who created this resource
- `created_at` (datetime, required) — Timestamp when the resource was created (ISO 8601)
- `updated_at` (datetime, required) — Timestamp when the resource was last updated (ISO 8601)
- `result` (object, optional, nullable) — Processing result with record counts
  - `total_records` (integer, required) — Total number of records in the uploaded file
  - `valid_records` (integer, required) — Number of records that passed validation
  - `rejected_records` (integer, required) — Number of records that failed validation
- `updated_by` (string, optional, nullable) — User who last updated this resource

## Examples

**Request**

```json
{
  "name": "july-emi-reminder",
  "users": [
    {
      "user_phone_number": "+919876543210",
      "user_identifier": "CUST-001",
      "app_variables": {
        "customer_name": "Rahul",
        "loan_amount": "12,500"
      },
      "app_overrides": {
        "initial_language_name": "Hindi"
      }
    },
    {
      "user_phone_number": "9876543211",
      "app_variables": {
        "customer_name": "Priya",
        "loan_amount": "8,000"
      }
    }
  ]
}
```

**Response**

```json
{
  "name": "july-emi-reminder",
  "cohort_id": "july-emi-reminder-xxxxx",
  "status": "processing",
  "source_type": "file_upload",
  "created_by": "user@example.com",
  "created_at": "2026-08-05T10:00:00Z",
  "updated_at": "2026-08-05T10:00:00Z",
  "result": {
    "total_records": 1000,
    "valid_records": 980,
    "rejected_records": 20
  },
  "updated_by": null,
  "cohort_category": "cohort"
}
```

**SDK Code**

```python User records (up to 1000)
import requests

url = "https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream"

payload = {
    "name": "july-emi-reminder",
    "users": [
        {
            "user_phone_number": "+919876543210",
            "user_identifier": "CUST-001",
            "app_variables": {
                "customer_name": "Rahul",
                "loan_amount": "12,500"
            },
            "app_overrides": { "initial_language_name": "Hindi" }
        },
        {
            "user_phone_number": "9876543211",
            "app_variables": {
                "customer_name": "Priya",
                "loan_amount": "8,000"
            }
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript User records (up to 1000)
const url = 'https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"name":"july-emi-reminder","users":[{"user_phone_number":"+919876543210","user_identifier":"CUST-001","app_variables":{"customer_name":"Rahul","loan_amount":"12,500"},"app_overrides":{"initial_language_name":"Hindi"}},{"user_phone_number":"9876543211","app_variables":{"customer_name":"Priya","loan_amount":"8,000"}}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go User records (up to 1000)
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream"

	payload := strings.NewReader("{\n  \"name\": \"july-emi-reminder\",\n  \"users\": [\n    {\n      \"user_phone_number\": \"+919876543210\",\n      \"user_identifier\": \"CUST-001\",\n      \"app_variables\": {\n        \"customer_name\": \"Rahul\",\n        \"loan_amount\": \"12,500\"\n      },\n      \"app_overrides\": {\n        \"initial_language_name\": \"Hindi\"\n      }\n    },\n    {\n      \"user_phone_number\": \"9876543211\",\n      \"app_variables\": {\n        \"customer_name\": \"Priya\",\n        \"loan_amount\": \"8,000\"\n      }\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby User records (up to 1000)
require 'uri'
require 'net/http'

url = URI("https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"july-emi-reminder\",\n  \"users\": [\n    {\n      \"user_phone_number\": \"+919876543210\",\n      \"user_identifier\": \"CUST-001\",\n      \"app_variables\": {\n        \"customer_name\": \"Rahul\",\n        \"loan_amount\": \"12,500\"\n      },\n      \"app_overrides\": {\n        \"initial_language_name\": \"Hindi\"\n      }\n    },\n    {\n      \"user_phone_number\": \"9876543211\",\n      \"app_variables\": {\n        \"customer_name\": \"Priya\",\n        \"loan_amount\": \"8,000\"\n      }\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java User records (up to 1000)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"july-emi-reminder\",\n  \"users\": [\n    {\n      \"user_phone_number\": \"+919876543210\",\n      \"user_identifier\": \"CUST-001\",\n      \"app_variables\": {\n        \"customer_name\": \"Rahul\",\n        \"loan_amount\": \"12,500\"\n      },\n      \"app_overrides\": {\n        \"initial_language_name\": \"Hindi\"\n      }\n    },\n    {\n      \"user_phone_number\": \"9876543211\",\n      \"app_variables\": {\n        \"customer_name\": \"Priya\",\n        \"loan_amount\": \"8,000\"\n      }\n    }\n  ]\n}")
  .asString();
```

```php User records (up to 1000)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream', [
  'body' => '{
  "name": "july-emi-reminder",
  "users": [
    {
      "user_phone_number": "+919876543210",
      "user_identifier": "CUST-001",
      "app_variables": {
        "customer_name": "Rahul",
        "loan_amount": "12,500"
      },
      "app_overrides": {
        "initial_language_name": "Hindi"
      }
    },
    {
      "user_phone_number": "9876543211",
      "app_variables": {
        "customer_name": "Priya",
        "loan_amount": "8,000"
      }
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp User records (up to 1000)
using RestSharp;

var client = new RestClient("https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"july-emi-reminder\",\n  \"users\": [\n    {\n      \"user_phone_number\": \"+919876543210\",\n      \"user_identifier\": \"CUST-001\",\n      \"app_variables\": {\n        \"customer_name\": \"Rahul\",\n        \"loan_amount\": \"12,500\"\n      },\n      \"app_overrides\": {\n        \"initial_language_name\": \"Hindi\"\n      }\n    },\n    {\n      \"user_phone_number\": \"9876543211\",\n      \"app_variables\": {\n        \"customer_name\": \"Priya\",\n        \"loan_amount\": \"8,000\"\n      }\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift User records (up to 1000)
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "name": "july-emi-reminder",
  "users": [
    [
      "user_phone_number": "+919876543210",
      "user_identifier": "CUST-001",
      "app_variables": [
        "customer_name": "Rahul",
        "loan_amount": "12,500"
      ],
      "app_overrides": ["initial_language_name": "Hindi"]
    ],
    [
      "user_phone_number": "9876543211",
      "app_variables": [
        "customer_name": "Priya",
        "loan_amount": "8,000"
      ]
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://apps.sarvam.ai/api/scheduling/v1/orgs/org_id/workspaces/workspace_id/campaigns/campaign_id/cohorts/stream")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```