Oso Cloud Policy API

The Policy API from Oso Cloud — 2 operation(s) for policy.

Operations 3

GET /policy #
POST /policy #
GET /policy_metadata #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/oso-policy-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

oso-policy-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Oso Cloud HTTP Centralized Authorization Data Policy API
  version: 0.1.0
  description: 'Oso Cloud exposes an HTTP API that you can use to make queries directly, without using one of the clients.For endpoints that require authentication, pass your API key as an HTTP Bearer Auth payload.For example, using curl: curl -H "Authorization: Bearer $OSO_AUTH" https://cloud.osohq.com/api/'
servers:
- url: https://api.osohq.com/api/
tags:
- name: Policy
paths:
  /policy:
    get:
      tags:
      - Policy
      description: Gets the currently active policy in Oso Cloud. The policy is expressed as a string containing [Polar](https://www.osohq.com/docs/modeling-in-polar/reference) code.
      operationId: get_policy
      parameters:
      - name: id
        in: query
        schema:
          type:
          - integer
          - 'null'
          format: int64
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetPolicyResult'
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
      security:
      - ApiKey: []
    post:
      tags:
      - Policy
      description: Updates the policy in Oso Cloud. The policy should be represented as a string containing [Polar](https://www.osohq.com/docs/modeling-in-polar/reference) code.
      operationId: post_policy
      parameters:
      - name: force
        in: query
        required: true
        schema:
          type: boolean
      - name: show_suggestions
        in: query
        required: true
        schema:
          type: boolean
      - name: fail_fast
        in: query
        required: true
        schema:
          type: boolean
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Policy'
        required: true
      responses:
        '200':
          description: The policy was updated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResult'
        '202':
          description: The policy was not updated because it is unchanged.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResult'
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SavePolicyError'
      security:
      - ApiKey: []
      x-codeSamples:
      - lang: javascript
        label: Node.js
        source: "import { Oso } from 'oso-cloud';\n\nconst apiKey = process.env.OSO_CLOUD_API_KEY;\nconst oso = new Oso(\"https://cloud.osohq.com\", apiKey);\n\n// Update policy with Polar code\nconst policyCode = `\n  actor User {}\n  resource Repository {\n    permissions = [\"read\", \"write\"];\n    roles = [\"owner\", \"maintainer\"];\n  }\n  has_role(user: User, \"owner\", repo: Repository) if\n    user.id = repo.owner_id;\n`;\nawait oso.policy(policyCode);\n"
      - lang: python
        label: Python
        source: "import os\nfrom oso_cloud import Oso\n\noso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))\n\n# Update policy with Polar code\npolicy_code = \"\"\"\nactor User {}\nresource Repository {\n    permissions = [\"read\", \"write\"];\n    roles = [\"owner\", \"maintainer\"];\n}\nhas_role(user: User, \"owner\", repo: Repository) if\n    user.id = repo.owner_id;\n\"\"\"\noso.policy(policy_code)\n"
      - lang: go
        label: Go
        source: "package main\n\nimport (\n    \"log\"\n    \"os\"\n    oso \"github.com/osohq/go-oso-cloud/v2\"\n)\n\nfunc main() {\n    apiKey := os.Getenv(\"OSO_CLOUD_API_KEY\")\n    osoClient := oso.NewClient(\"https://cloud.osohq.com\", apiKey)\n\n// Update policy with Polar code\npolicyCode := `\nactor User {}\nresource Repository {\n    permissions = [\"read\", \"write\"];\n    roles = [\"owner\", \"maintainer\"];\n}\nhas_role(user: User, \"owner\", repo: Repository) if\n    user.id = repo.owner_id;\n`\n    err := osoClient.Policy(policyCode)\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n"
      - lang: java
        label: Java
        source: "package com.mycompany;\n\nimport java.io.IOException;\nimport com.osohq.oso_cloud.Oso;\nimport com.osohq.oso_cloud.api.ApiException;\n\npublic class App {\n    public static void main(String[] args) {\n        String apiKey = System.getenv(\"OSO_CLOUD_API_KEY\");\n        Oso oso = new Oso(apiKey);\n\n// Update policy with Polar code\nString policyCode = \"\"\"\n    actor User {}\n    resource Repository {\n        permissions = [\"read\", \"write\"];\n        roles = [\"owner\", \"maintainer\"];\n    }\n    has_role(user: User, \"owner\", repo: Repository) if\n        user.id = repo.owner_id;\n    \"\"\";\n        try {\n            oso.policy(policyCode);\n        } catch (IOException | ApiException e) {\n            System.err.println(\"Error updating policy: \" + e.getMessage());\n        }\n    }\n}\n"
      - lang: ruby
        label: Ruby
        source: "require 'oso-cloud'\n\napi_key = ENV.fetch('OSO_CLOUD_API_KEY', nil)\noso = OsoCloud::Oso.new(url: \"https://cloud.osohq.com\", api_key: api_key)\n\n# Update policy with Polar code\npolicy_code = <<~POLAR\n  actor User {}\n  resource Repository {\n    permissions = [\"read\", \"write\"];\n    roles = [\"owner\", \"maintainer\"];\n  }\n  has_role(user: User, \"owner\", repo: Repository) if\n    user.id = repo.owner_id;\nPOLAR\noso.policy(policy_code)\n"
      - lang: csharp
        label: C#
        source: "using OsoCloud;\n\nstring? apiKey = Environment.GetEnvironmentVariable(\"OSO_CLOUD_API_KEY\");\nvar oso = new Oso(\"https://api.osohq.com\", apiKey);\n\n// Update policy with Polar code\nvar policyCode = @\"\n    actor User {}\n    resource Repository {\n        permissions = [\"\"read\"\", \"\"write\"\"];\n        roles = [\"\"owner\"\", \"\"maintainer\"\"];\n    }\n    has_role(user: User, \"\"owner\"\", repo: Repository) if\n        user.id = repo.owner_id;\n\";\nawait oso.Policy(policyCode);\n"
  /policy_metadata:
    get:
      tags:
      - Policy
      description: Returns metadata about the currently active policy.
      operationId: get_policy_metadata
      parameters:
      - name: id
        in: query
        schema:
          type:
          - integer
          - 'null'
          format: int64
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetPolicyMetadataResult'
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
      security:
      - ApiKey: []
      x-codeSamples:
      - lang: javascript
        label: Node.js
        source: 'import { Oso } from ''oso-cloud'';


          const apiKey = process.env.OSO_CLOUD_API_KEY;

          const oso = new Oso("https://cloud.osohq.com", apiKey);


          // Get policy metadata

          const metadata = await oso.getPolicyMetadata();


          // Access resource information

          console.log(metadata.resources.keys());        // List all resources

          console.log(metadata.resources.get("Repository")); // Get specific resource metadata

          '
      - lang: python
        label: Python
        source: 'import os

          from oso_cloud import Oso


          oso = Oso(api_key=os.environ.get(''OSO_CLOUD_API_KEY'', None))


          # Get policy metadata

          metadata = oso.get_policy_metadata()


          # Access resource information

          print(metadata.resources.keys())               # List all resources

          print(metadata.resources["Repository"])        # Get specific resource metadata

          '
      - lang: go
        label: Go
        source: "package main\n\nimport (\n    \"log\"\n    \"os\"\n    oso \"github.com/osohq/go-oso-cloud/v2\"\n)\n\nfunc main() {\n    apiKey := os.Getenv(\"OSO_CLOUD_API_KEY\")\n    osoClient := oso.NewClient(\"https://cloud.osohq.com\", apiKey)\n\n// Get policy metadata\n    metadata, err := osoClient.GetPolicyMetadata()\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n\n// Access resource information\nfor resourceName := range metadata.Resources {\n    fmt.Printf(\"Resource: %s\\n\", resourceName)\n}\n"
      - lang: java
        label: Java
        source: "package com.mycompany;\n\nimport java.io.IOException;\nimport com.osohq.oso_cloud.Oso;\nimport com.osohq.oso_cloud.api.ApiException;\n\npublic class App {\n    public static void main(String[] args) {\n        String apiKey = System.getenv(\"OSO_CLOUD_API_KEY\");\n        Oso oso = new Oso(apiKey);\n\n        // Get policy metadata\n        try {\n            PolicyMetadata metadata = oso.getPolicyMetadata();\n            \n            // Access resource information\n            System.out.println(metadata.getResources().keySet());\n        } catch (IOException | ApiException e) {\n            System.err.println(\"Error getting policy metadata: \" + e.getMessage());\n        }\n    }\n}\n"
      - lang: ruby
        label: Ruby
        source: 'require ''oso-cloud''


          api_key = ENV.fetch(''OSO_CLOUD_API_KEY'', nil)

          oso = OsoCloud::Oso.new(url: "https://cloud.osohq.com", api_key: api_key)


          # Get policy metadata

          metadata = oso.get_policy_metadata


          # Access resource information

          puts metadata.resources.keys

          '
      - lang: csharp
        label: C#
        source: 'using OsoCloud;


          string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");

          var oso = new Oso("https://api.osohq.com", apiKey);


          // Get policy metadata

          var metadata = await oso.GetPolicyMetadata();


          // Access resource information

          Console.WriteLine(string.Join(", ", metadata.Resources.Keys));

          '
components:
  schemas:
    ApiResult:
      type: object
      required:
      - message
      properties:
        message:
          type: string
    GetPolicyMetadataResult:
      type: object
      required:
      - metadata
      properties:
        metadata:
          $ref: '#/components/schemas/PolicyMetadata'
    Policy:
      type: object
      required:
      - src
      properties:
        filename:
          type:
          - string
          - 'null'
        src:
          type: string
    TestSummary:
      description: Results of executing a single test. Sent to `oso-cloud` CLI as JSON.
      type: object
      required:
      - name
      - passed
      - total
      properties:
        name:
          description: Name of test.
          type: string
        passed:
          description: How many assertions passed?
          type: integer
          format: uint
          minimum: 0
        total:
          description: How many assertions in total?
          type: integer
          format: uint
          minimum: 0
    PolicyTestResult:
      description: Result of a Policy test API request. Sent to `oso-cloud` CLI as JSON.
      type: object
      required:
      - errors
      - success
      - tests
      properties:
        success:
          description: Did the policy test succeed?
          type: boolean
        errors:
          description: What errors did we encounter?
          type: array
          items:
            $ref: '#/components/schemas/PolicyError'
        tests:
          description: What tests did we execute?
          type: array
          items:
            $ref: '#/components/schemas/TestSummary'
    PolicyError:
      description: Error report for a failed Polar policy test, to be displayed to user. Sent to `oso-cloud` CLI as JSON.
      type: object
      required:
      - error_type
      - message
      properties:
        error_type:
          description: Type of error encountered.
          allOf:
          - $ref: '#/components/schemas/PolicyFailure'
        message:
          description: Error message to display to the user.
          type: string
    PolicyFailure:
      description: All known failure modes for a submitted policy test. Encountering any of these scenarios means the policy test has failed.
      oneOf:
      - description: Polar file failed validation.
        type: string
        enum:
        - ValidationFailed
      - description: An assertion failed in an executed test.
        type: string
        enum:
        - AssertionFailed
      - description: Server hit an unexpected error.
        type: string
        enum:
        - ServerError
    GetPolicyResult:
      type: object
      properties:
        policy:
          allOf:
          - $ref: '#/components/schemas/Policy'
    PolicyMetadata:
      type: object
      required:
      - resources
      properties:
        resources:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/ResourceBlockData'
    SavePolicyError:
      oneOf:
      - type: object
        required:
        - error_type
        - message
        properties:
          error_type:
            type: string
            enum:
            - Generic
          message:
            type: string
      - type: object
        required:
        - error_type
        - errors
        - message
        properties:
          error_type:
            type: string
            enum:
            - Validation
          message:
            type: string
          errors:
            type: array
            items:
              $ref: '#/components/schemas/PolicyError'
      - type: object
        required:
        - error_type
        - message
        - test_results
        properties:
          error_type:
            type: string
            enum:
            - TestsFailed
          message:
            type: string
          test_results:
            $ref: '#/components/schemas/PolicyTestResult'
    ApiError:
      type: object
      required:
      - message
      properties:
        message:
          type: string
    ResourceBlockData:
      type: object
      required:
      - permissions
      - relations
      - roles
      properties:
        roles:
          type: array
          items:
            type: string
        permissions:
          type: array
          items:
            type: string
        relations:
          type: object
          additionalProperties:
            type: string
  securitySchemes:
    ApiKey:
      description: Requires an API key to access.
      type: http
      scheme: bearer
      bearerFormat: Bearer e_0123_123_token0123