{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenRouter Ultra V2 – MCP Server & Deterministic JSON API",
    "description": "Zero-cold-start OpenRouter proxy and native MCP server for AI agent tool calls.\n\nDelivers deterministic JSON self-healing (REST & SSE streaming), <5ms local semantic routing, automated vision token optimization, shadow model benchmarking, context compression, and 50-row dataset batching.",
    "version": "2.0",
    "x-build-id": "wBAXFJSNjGtTFNxjI"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/chriskelch77~openrouter-ultra/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-chriskelch77-openrouter-ultra",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/chriskelch77~openrouter-ultra/runs": {
      "post": {
        "operationId": "runs-sync-chriskelch77-openrouter-ultra",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/chriskelch77~openrouter-ultra/run-sync": {
      "post": {
        "operationId": "run-sync-chriskelch77-openrouter-ultra",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "required": [
          "mode"
        ],
        "properties": {
          "mode": {
            "title": "Execution Mode",
            "enum": [
              "api",
              "batch"
            ],
            "type": "string",
            "description": "Select 'api' to launch the zero-cold-start Server Actor with OpenRouter proxy endpoints and native MCP server integration (/sse, /mcp) for AI agent tool calls, or 'batch' to run high-throughput chunked dataset orchestration.",
            "default": "api"
          },
          "openRouterApiKey": {
            "title": "OpenRouter API Key (BYOK)",
            "type": "string",
            "description": "Your Bring-Your-Own-Key (BYOK) OpenRouter API credential for authenticating upstream LLM requests across OpenAI, Anthropic, Google Gemini, Meta Llama, and DeepSeek providers. Stored encrypted."
          },
          "modelChain": {
            "title": "Model Fallback Chain",
            "type": "array",
            "description": "Ordered list of OpenRouter model IDs for automatic failover. If the primary model experiences rate limits (HTTP 429), provider outages (5xx), or timeouts, the OpenRouter proxy seamlessly retries with the next model in the chain.",
            "items": {
              "type": "string"
            },
            "default": [
              "openai/gpt-4o-mini",
              "anthropic/claude-3-haiku"
            ]
          },
          "policyPreset": {
            "title": "Policy Preset",
            "enum": [
              "ultra-fast",
              "ultra-smart",
              "ultra-private",
              "ultra-json",
              "ultra-batch",
              "ultra-extract",
              "ultra-debug",
              "custom"
            ],
            "type": "string",
            "description": "Predefined intelligent routing and execution profile: 'ultra-fast' minimizes latency, 'ultra-smart' enables deterministic JSON repair and debug artifacts, 'ultra-private' enforces PII masking and zero data retention, 'ultra-json' and 'ultra-extract' enforce strict JSON schema validation for AI agent tool calls.",
            "default": "custom"
          },
          "taskClass": {
            "title": "Task Class",
            "enum": [
              "auto",
              "chat",
              "extraction",
              "classification",
              "reasoning",
              "coding",
              "embedding"
            ],
            "type": "string",
            "description": "Semantic workload hint for the smart routing engine ('auto', 'chat', 'extraction', 'classification', 'reasoning', 'coding', 'embedding'). 'auto' uses the local ONNX semantic edge classifier to infer intent in <5ms with zero token cost.",
            "default": "auto"
          },
          "route": {
            "title": "Target API Route",
            "enum": [
              "chat",
              "responses",
              "anthropic",
              "embeddings"
            ],
            "type": "string",
            "description": "Target OpenRouter proxy protocol route ('chat' for OpenAI Chat Completions, 'responses' for OpenRouter Responses API, 'anthropic' for Claude Messages format, or 'embeddings' for vector embeddings).",
            "default": "chat"
          },
          "maxCostPerRunUsd": {
            "title": "Max Cost Per Run (USD)",
            "minimum": 0,
            "type": "number",
            "description": "Hard cumulative USD budget ceiling per Actor run. Combined with Pure Pay-Per-Event (PPE) circuit-breaker enforcement, the Actor immediately halts processing once this threshold is reached.",
            "default": 5
          },
          "maxCostPerRequestUsd": {
            "title": "Max Cost Per Request (USD)",
            "minimum": 0,
            "type": "number",
            "description": "Maximum allowed estimated USD token cost for a single API request or AI agent tool call."
          },
          "timeoutMs": {
            "title": "Timeout (ms)",
            "minimum": 1000,
            "type": "integer",
            "description": "Strict per-model HTTP timeout in milliseconds (default 30,000ms) to prevent hung upstream LLM providers from consuming Server Actor compute margins.",
            "default": 30000
          },
          "latencyTargetMs": {
            "title": "Latency Target (ms)",
            "minimum": 100,
            "type": "integer",
            "description": "Target end-to-end latency in milliseconds for the smart routing engine. Values below 3000ms prioritize low-latency models."
          },
          "maxRetries": {
            "title": "Max Retries",
            "minimum": 0,
            "type": "integer",
            "description": "Maximum number of upstream retry attempts per request when recoverable HTTP 429 or 5xx errors occur.",
            "default": 2
          },
          "enableExactCache": {
            "title": "Enable Exact Response Cache",
            "type": "boolean",
            "description": "Serve identical LLM requests from the memory-bounded LRU cache (20MB cap) and Apify Key-Value Store using deterministic SHA-256 request hashing.",
            "default": true
          },
          "cacheTtlSeconds": {
            "title": "Cache TTL (seconds)",
            "minimum": 1,
            "type": "integer",
            "description": "Time-to-live in seconds for cached OpenRouter proxy responses in the Apify Key-Value Store.",
            "default": 86400
          },
          "cacheNamespace": {
            "title": "Cache Namespace",
            "type": "string",
            "description": "Logical namespace key to isolate cached LLM responses across multi-tenant workflows or AI agent environments.",
            "default": "default"
          },
          "enablePrefixCache": {
            "title": "Enable Prefix Cache",
            "type": "boolean",
            "description": "Enable prefix-based prompt caching hints for supported upstream providers to reduce input token costs.",
            "default": true
          },
          "userScopedCache": {
            "title": "User Scoped Cache",
            "type": "boolean",
            "description": "Scope cache entries by caller identity when multi-user headers are supplied.",
            "default": true
          },
          "jsonStrictMode": {
            "title": "Enable Deterministic JSON Self-Healing",
            "type": "boolean",
            "description": "Automatically strip markdown code fences, prose wrappers, trailing commas, unquoted keys, and single quotes to guarantee valid deterministic JSON output.",
            "default": true
          },
          "jsonSchema": {
            "title": "JSON Schema",
            "type": "object",
            "description": "Strict JSON Schema object (Draft-07 / Ajv) used to validate and self-heal structured LLM outputs in API, Batch, and MCP ultra_extract tool calls."
          },
          "enableDeterministicRepair": {
            "title": "Enable Deterministic Repair",
            "type": "boolean",
            "description": "Execute zero-latency deterministic regex and AST-style JSON repair before falling back to model-assisted repair.",
            "default": true
          },
          "maxRepairAttempts": {
            "title": "Max Repair Attempts",
            "minimum": 0,
            "type": "integer",
            "description": "Maximum number of JSON repair passes before returning a schema validation error.",
            "default": 1
          },
          "enableRepairModel": {
            "title": "Enable Repair Model",
            "type": "boolean",
            "description": "Invoke a secondary fast LLM to heal structurally corrupted JSON when deterministic repair is insufficient.",
            "default": false
          },
          "repairModel": {
            "title": "Repair Model Name",
            "type": "string",
            "description": "OpenRouter model identifier used for secondary JSON self-healing when enableRepairModel is active.",
            "default": "openai/gpt-4o-mini"
          },
          "enableDebugArtifacts": {
            "title": "Enable Debug Artifacts",
            "type": "boolean",
            "description": "Persist detailed JSON parse and Ajv schema validation diagnostics to the 'ultra-debug' Key-Value Store for observability.",
            "default": true
          },
          "piiMasking": {
            "title": "Enable PII Masking",
            "type": "boolean",
            "description": "Automatically scrub email addresses, phone numbers, credit cards, and SSNs from prompts before forwarding to OpenRouter.",
            "default": false
          },
          "zdrOnly": {
            "title": "Zero Data Retention Only",
            "type": "boolean",
            "description": "Restrict routing exclusively to OpenRouter upstream providers that enforce Zero Data Retention (ZDR) compliance.",
            "default": false
          },
          "redactLogs": {
            "title": "Redact Logs",
            "type": "boolean",
            "description": "Scrub sensitive fields and PII from Server Actor console logs and trace metadata.",
            "default": true
          },
          "datasetId": {
            "title": "Target Dataset ID (Batch Mode Only)",
            "type": "string",
            "description": "Source Apify Dataset ID whose items will be processed in parallel by the batch orchestrator with exponential backoff and 50-row chunked writes."
          },
          "requestTemplate": {
            "title": "Request Template (Batch Mode Only)",
            "type": "object",
            "description": "OpenRouter request payload template supporting {{fieldName}} and nested {{object.path}} placeholders injected from each source dataset row."
          },
          "inputMapping": {
            "title": "Input Field Mapping",
            "type": "object",
            "description": "Optional field alias mapping from source dataset columns to requestTemplate variables."
          },
          "sampleSize": {
            "title": "Batch Sample Size",
            "minimum": 1,
            "type": "integer",
            "description": "Maximum number of dataset rows to process during a batch run (useful for pilot testing and cost estimation).",
            "default": 10
          },
          "deadLetterDatasetId": {
            "title": "Dead Letter Dataset ID",
            "type": "string",
            "description": "Optional Apify Dataset ID where failed batch rows are written with retry protection for post-run inspection and replay."
          },
          "webhookUrl": {
            "title": "Completion Webhook URL",
            "type": "string",
            "description": "HTTPS endpoint to receive a JSON summary payload (runId, total, success, failed, timestamp) when batch orchestration finishes."
          },
          "shadowModel": {
            "title": "Shadow Benchmark Model (Canary Mode)",
            "type": "string",
            "description": "Optional OpenRouter model ID for asynchronous A/B shadow benchmarking. Duplicates traffic in fire-and-forget mode after returning the primary response and records latency, cost, similarity, and schema pass/fail to the 'ultra-shadow-benchmarks' KV store."
          },
          "autoCompressContext": {
            "title": "Auto-Summarize Context Compression",
            "type": "boolean",
            "description": "Automatically prevent 400 Context Length Exceeded errors and cap input costs by keeping the system prompt (first 10%) and most recent 20% of messages while summarizing the middle 70% via a fast model when token limits are exceeded.",
            "default": false
          },
          "maxInputTokens": {
            "title": "Max Input Tokens Threshold",
            "minimum": 100,
            "type": "integer",
            "description": "Estimated input token threshold that triggers automatic middle-out context compression when autoCompressContext is enabled."
          },
          "enableVisionOptimizer": {
            "title": "Enable Automated Vision Token Optimizer",
            "type": "boolean",
            "description": "Automatically intercept Base64 image_url payloads, detect target model tile constraints (e.g. 512x512 tiles for OpenAI, 1568px for Anthropic), and downscale images with sharp to eliminate wasted vision padding tokens.",
            "default": true
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}