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

# Validate Workflow

POST https://api.onepin.ai/api/v1/workflows/validate
Content-Type: application/json

Validate a workflow `definition` against the FULL run-start bundle, without saving it.

Runs every gate a run start would apply — `validate_definition` (structural /
port-contract validation) plus every `preflight_definition` gate (source/output
completeness, locale routing, translator coverage) — not the narrower save-time
subset `POST /workflows` and `PUT /workflows/{id}` use. A definition that saves
cleanly can still fail every one of these; that gap is exactly what this endpoint
exists to close before a definition is ever persisted.

Always returns 200. `valid: false` with a populated `errors` list is itself a
successful answer to "is this valid?" — 422 stays reserved for a malformed request
body. A true entitlement refusal (a plan-gated node/provider the caller's plan
cannot use, `ErrorCode.FORBIDDEN`) is reported separately in `blocked`: not fixable
by editing the graph. A voice-ownership violation (unauthorized/unknown/unsupported
voice reference) is `ErrorCode.VALIDATION_ERROR` instead — an LLM fixes it the same
way it fixes any other rule, by picking a different voice/model — so it is folded
into `errors` like every other rule violation, not `blocked`.

No side effects — nothing is read from or written to the `workflows` table.
Requires at least `editor` role. Scope is `workflows:write` deliberately: a caller
who cannot create a workflow should not receive a validation result that exists
only to gate creation.

Reference: https://onepin.ai/docs/reference/api-reference/workflows/validate-workflow-api-v-1-workflows-validate-post

## Authentication

- `Authorization` header (bearer token, required) — Clerk JWT token
- `Authorization` header (bearer token, required) — Onepin live API key (`op_live_...`). Test and public keys are reserved in Phase 1.

## Servers

- `https://api.onepin.ai` (prod, default)
- `https://dev-api.onepin.ai` (dev)

## Request

### Headers

- `X-Workspace-Id` (string, optional, nullable)

### Body (application/json)

This endpoint expects a WorkflowValidateIn.

- `definition` (WorkflowDefinition-Input, required) — Graph and execution config to validate. Nothing is persisted.

## Response

### 200

Successful Response

- `data` (WorkflowValidateOut, required) — Result of validating a definition against the full run-start bundle, without saving it. `valid` reflects `errors` only — a non-empty `blocked` does not flip it to `False`, since `blocked` entries are not graph defects (see `ValidationBlockedOut`).
- `meta` (Meta, required)

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### WorkflowDefinition-Input

- `graph` (GraphDefinition-Input, optional)
- `execution` (ExecutionDefinition, optional)

### WorkflowValidateOut

Result of validating a definition against the full run-start bundle, without saving it. `valid` reflects `errors` only — a non-empty `blocked` does not flip it to `False`, since `blocked` entries are not graph defects (see `ValidationBlockedOut`).

- `valid` (boolean, required) — True only when `errors` is empty. Not affected by `blocked`.
- `summary` (map from string to any, required) — Presentation summary of the definition (see `build_definition_summary`); populated on both outcomes.
- `errors` (list of ValidationDetailOut, optional) — Structural / run-start rule violations. Editable by changing the graph.
- `warnings` (list of ValidationDetailOut, optional) — Non-blocking structural warnings (e.g. `cycle`). Never affects `valid`.
- `blocked` (list of ValidationBlockedOut, optional) — Entitlement refusals. Not fixable by editing the graph.

### Meta

- `request_id` (string, required)
- `timestamp` (datetime, required)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### GraphDefinition-Input

- `nodes` (list of GraphNode, optional)
- `edges` (list of GraphEdge, optional)

### ExecutionDefinition

- `steps` (list of string, optional)
- `params` (map from string to any, optional)

### ValidationDetailOut

One structural or run-start rule violation. Mirrors the narrow subset of a raw ``ValidationDetail`` (``dict[str, object]``, see ``services/workflow/validator.py``) an LLM-facing caller needs to act on a rule. The raw dict can carry additional rule-specific keys (``edge_id``, ``source_type``, ...); those are intentionally dropped here rather than relayed, since a workaround is looked up by ``rule``, not by the extra fields.

- `rule` (string, required) — Machine-readable rule identifier, e.g. `incompatible_ports`.
- `message` (string, required) — Human-readable, localized explanation of the violation.
- `node_id` (string, optional, nullable) — The node this violation is about, when the rule names one.
- `node_name` (string, optional, nullable) — Display name of `node_id`, when available.

### ValidationBlockedOut

An entitlement refusal (403-origin): not fixable by editing the graph.

- `code` (string, required) — The `ErrorCode` the refusal was raised with, e.g. `FORBIDDEN`.
- `message` (string, required) — Human-readable, localized explanation of the refusal.

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

### GraphNode

- `id` (string, required)
- `type` (enum, required)
  - Allowed values: `source_script`, `operator_translator`, `operator_normalizer`, `operator_generator`, `operator_phoneme_injector`, `sink_preview`, `validator_error_rate`, `validator_naturalness`, `validator_noise`, `validator_pronunciation`, `operator_pronunciation_corrector`
- `position` (NodePosition, required)
- `name` (string, optional, nullable)
- `config` (map from string to any, optional)
- `config_version` (integer, optional, default: 1)

### GraphEdge

- `id` (string, required)
- `source` (string, required)
- `sourcePort` (string, required)
- `target` (string, required)
- `targetPort` (string, required)

### NodePosition

- `x` (double, required)
- `y` (double, required)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "data": {
    "valid": true,
    "summary": {},
    "errors": [
      {
        "rule": "string",
        "message": "string",
        "node_id": "string",
        "node_name": "string"
      }
    ],
    "warnings": [
      {
        "rule": "string",
        "message": "string",
        "node_id": "string",
        "node_name": "string"
      }
    ],
    "blocked": [
      {
        "code": "string",
        "message": "string"
      }
    ]
  },
  "meta": {
    "request_id": "string",
    "timestamp": "2024-01-15T09:30:00Z"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.onepin.ai/api/v1/workflows/validate"

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

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

print(response.json())
```

```javascript
const url = 'https://api.onepin.ai/api/v1/workflows/validate';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

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.onepin.ai/api/v1/workflows/validate"

	payload := strings.NewReader("{}")

	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.onepin.ai/api/v1/workflows/validate")

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 = "{}"

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.onepin.ai/api/v1/workflows/validate")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.onepin.ai/api/v1/workflows/validate', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.onepin.ai/api/v1/workflows/validate");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.onepin.ai/api/v1/workflows/validate")! 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()
```