> 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 question set (config-as-code converge)

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

Idempotently converge a repo-defined question set. Identity is the slug within the organization. A hash-only probe skips the payload in the steady state (a miss is a normal 200 `definitionRequired`, not an error); a full request creates the set, or appends a draft version when the questions, input mapping or model differ. Set dryRun to plan without writing, onConflict: "overwrite" to converge over dashboard or API edits, expectedRemoteHash to bind an apply to its dry run, and release: "publish" to publish the latest version. Ensure never deletes a set or a version.

Reference: https://docs.runtype.com/api-reference/runtype-api/question-sets/ensure-question-set-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.

- `slug` (string, required) — Identity, unique in the organization: lowercase letters, digits, `-` and `_`, up to 64.
- `contentHash` (string, optional)
- `definition` (V1QuestionSetsEnsurePostRequestBodyContentApplicationJsonSchemaDefinition, optional)
- `dryRun` (boolean, optional)
- `expectedRemoteHash` (string, optional)
- `onConflict` (enum, optional)
  - Allowed values: `error`, `overwrite`
- `release` (enum, optional)
  - Allowed values: `none`, `publish`

## Response

### 200

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

- `QuestionSetEnsureResponse`

## Errors

### 400 Bad Request Error

Invalid request or invalid questions

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

### 401 Unauthorized Error

Unauthorized

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

### 403 Forbidden Error

Insufficient permissions, or no organization context

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

### 404 Not Found Error

The question set was removed while the converge ran

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

### 409 Conflict Error

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

- `code` (string, required) — external_modification, remote_changed, or a question set code such as QUESTION_SET_SLUG_TAKEN.
- `error` (string, required)
- `currentHash` (string, optional, nullable)
- `lastModifiedSource` (string, optional)
- `modifiedAt` (string, optional, nullable)

### 422 Unprocessable Entity Error

The 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

### V1QuestionSetsEnsurePostRequestBodyContentApplicationJsonSchemaDefinition

- `name` (string, required)
- `questions` (map from string to any, required) — Judgment questions keyed by question id, validated like `POST /v1/question-sets`.
- `description` (string, optional, nullable)
- `inputMapping` (map from string to string, optional, nullable)
- `model` (string, optional, nullable)

### QuestionSetEnsureResponse0

- `contentHash` (string, required) — Server-computed canonical content hash. Clients should echo this hash in probes.
- `publishedVersionNumber` (integer, required, nullable) — The version executions resolve when they name none; null until a publish.
- `questionSetId` (string, required)
- `result` (enum, required)
  - Allowed values: `unchanged`, `created`, `updated`
- `versionId` (string, required, nullable) — The latest version, which the converged definition matches.
- `versionNumber` (integer, required, nullable)

### QuestionSetEnsureResponse1

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

### QuestionSetEnsureResponse2

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

### V1QuestionSetsEnsurePostResponsesContentApplicationJsonSchemaDetailsItems

- `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, …).

## Examples

**Request**

```json
{
  "slug": "string"
}
```

**Response**

```json
{
  "contentHash": "string",
  "publishedVersionNumber": 1,
  "questionSetId": "string",
  "result": "unchanged",
  "versionId": "string",
  "versionNumber": 1
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/question-sets/ensure"

payload = { "slug": "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/question-sets/ensure';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"slug":"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/question-sets/ensure"

	payload := strings.NewReader("{\n  \"slug\": \"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/question-sets/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  \"slug\": \"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/question-sets/ensure")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"slug\": \"string\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

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

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

```csharp
using RestSharp;

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

```swift
import Foundation

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

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

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