> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Ensure schedule (config-as-code converge)

POST https://api.runtype.com/v1/schedules/ensure
Content-Type: application/json

Idempotently converge a repo-defined schedule on a standalone flow or agent. Identity is name + target + account scope; the target may name the flow or agent instead of carrying its id, so one definition works in every environment. Hash-only probes skip the payload in the steady state (a miss is a normal 200 `definitionRequired` response); full requests create the schedule or update it when the canonical content hash differs. Set dryRun to plan without writing (CI drift gate) and onConflict: "overwrite" to converge over dashboard/API edits. Omit `enabled` to leave a paused schedule paused. Ensure never deletes; schedules owned by a product surface are never matched.

Reference: https://docs.runtype.com/api-reference/runtype-api/schedules/ensure-schedule-config-as-code-converge

## Authentication

- `Authorization` header (bearer token, required) — API key or Clerk session token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Body (application/json)

This endpoint expects an object.

- `name` (string, required)
- `target` (ScheduleEnsureTarget, required)
- `contentHash` (string, optional)
- `definition` (ScheduleEnsureDefinition, optional)
- `dryRun` (boolean, optional)
- `expectedRemoteHash` (string, optional)
- `onConflict` (enum, optional)
  - Allowed values: `error`, `overwrite`

## Response

### 200

Converge result: unchanged | created | updated | definitionRequired (hash miss — retry with the full definition) | plan (dryRun)

- `ScheduleEnsureResponse`

## Errors

### 400 Bad Request Error

Validation error, SCHEDULE_AGENT_CONFIG_UNSUPPORTED for an agent a schedule cannot run, or RUNTIME_LANE_INELIGIBLE for a flow the batch host cannot run

- `error` (string, required)
- `details` (list of ScheduleValidationErrorDetailsItems, optional)
- `code` (string, optional) — Stable error code. SCHEDULE_AGENT_CONFIG_UNSUPPORTED: the target agent uses config a schedule cannot supply; `details[].path` names it. RUNTIME_LANE_INELIGIBLE: the target flow uses capabilities the batch host cannot run; `reasons` names them.
- `message` (string, optional) — Human-readable error message.
- `reasons` (list of string, optional) — With RUNTIME_LANE_INELIGIBLE: stable `ineligible:*` reason codes, e.g. `ineligible:wait-until`.

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 402 Payment Required Error

Plan limit exceeded (cron frequency or active schedule count)

- `error` (string, required)
- `details` (list of ScheduleEntitlementErrorDetailsItems, optional)
- `code` (string, optional) — Stable error code (e.g. ACTIVE_SCHEDULE_LIMIT, SCHEDULE_FREQUENCY_LIMIT).
- `message` (string, optional) — Human-readable error message.
- `upgradeUrl` (string, optional) — Dashboard-relative URL to the billing/upgrade page.

### 403 Forbidden Error

Insufficient permissions

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 404 Not Found Error

Target not found

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 409 Conflict Error

Conflict: external_modification (last write was not ensure; pass onConflict: "overwrite") or remote_changed (expectedRemoteHash guard)

- `code` (enum, required)
  - Allowed values: `external_modification`, `remote_changed`
- `error` (string, required)
- `currentHash` (string, optional, nullable)
- `lastModifiedSource` (string, optional)
- `modifiedAt` (string, optional, nullable)

### 422 Unprocessable Entity Error

Submitted contentHash does not match the server-recomputed canonical hash

- `code` (enum, required)
  - Allowed values: `content_hash_mismatch`
- `contentHash` (string, required) — The server-computed canonical hash of the submitted definition.
- `error` (string, required)

### 500 Internal Server Error

Internal server error

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

## Types

### ScheduleEnsureTarget

- `agentId` (string, optional)
- `agentName` (string, optional)
- `flowId` (string, optional)
- `flowName` (string, optional)

### ScheduleEnsureDefinition

- `name` (string, required)
- `target` (ScheduleEnsureTarget, required)
- `trigger` (ScheduleEnsureDefinitionTrigger, required)
- `enabled` (boolean, optional) — Omit to leave the current paused/active state untouched; new schedules start enabled.
- `executionOptions` (ScheduleEnsureDefinitionExecutionOptions, optional)
- `inputs` (map from string to any, optional)
- `messages` (list of map from string to any, optional)
- `recordFilter` (map from string to any, optional)
- `recordIds` (list of string, optional)
- `recordType` (string, optional)

### ScheduleEnsureResponse0

- `contentHash` (string, required) — Server-computed canonical content hash. Clients should echo this hash in probes.
- `result` (enum, required)
  - Allowed values: `unchanged`, `created`, `updated`
- `scheduleId` (string, required)

### ScheduleEnsureResponse1

- `result` (enum, required)
  - Allowed values: `definitionRequired`

### ScheduleEnsureResponse2

- `changedKeys` (list of string, required)
- `changes` (enum, required)
  - Allowed values: `none`, `create`, `update`
- `contentHash` (string, required)
- `result` (enum, required)
  - Allowed values: `plan`
- `remoteHash` (string, optional)
- `scheduleId` (string, optional)

### ScheduleValidationErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### ScheduleEntitlementErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### ScheduleEnsureDefinitionTrigger

- `type` (enum, required)
  - Allowed values: `recurring`, `one_time`
- `cron` (string, optional)
- `runAt` (datetime, optional)
- `timezone` (string, optional)

### ScheduleEnsureDefinitionExecutionOptions

- `chunkSize` (integer, optional)
- `flowTimeoutMs` (integer, optional)
- `loggingPolicy` (enum, optional)
  - Allowed values: `default`, `on`, `off`
- `maxRetries` (integer, optional)
- `modelOverride` (string, optional)
- `progressFlushSize` (integer, optional)
- `recordConcurrency` (integer, optional)
- `skipCacheWarm` (boolean, optional)
- `stepTimeoutMs` (integer, optional)
- `timeoutMs` (integer, optional)

## Examples

**Request**

```json
{
  "name": "string"
}
```

**Response**

```json
{
  "contentHash": "string",
  "result": "unchanged",
  "scheduleId": "string"
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/schedules/ensure"

payload = { "name": "string" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.runtype.com/v1/schedules/ensure';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"string"}'
};

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

```go
package main

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

func main() {

	url := "https://api.runtype.com/v1/schedules/ensure"

	payload := strings.NewReader("{\n  \"name\": \"string\"\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/schedules/ensure")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"string\"\n}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.runtype.com/v1/schedules/ensure")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/schedules/ensure', [
  'body' => '{
  "name": "string"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/schedules/ensure");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["name": "string"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/schedules/ensure")! 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()
```