> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute BRK

> Executes a BRK with the provided input values

This endpoint executes a BRK with the provided input values. It processes the BRK, including any dependencies, and returns the result. The input values must match the schema of the BRK. You must have at least viewer permissions for the BRK to execute it.

## Request

<ParamField body="brxId" type="string" required>
  The ID of the BRK to execute
</ParamField>

<ParamField body="schemaValues" type="object" required>
  The input values for the BRK, matching its schema
</ParamField>

<ParamField body="executionOptions" type="object" optional>
  Optional execution options for the BRK

  <Expandable title="properties">
    <ParamField body="maxTokens" type="number" optional>
      Maximum number of tokens to generate
    </ParamField>

    <ParamField body="temperature" type="number" optional>
      Temperature for sampling (0.0 to 1.0)
    </ParamField>

    <ParamField body="topP" type="number" optional>
      Top-p sampling parameter (0.0 to 1.0)
    </ParamField>

    <ParamField body="model" type="string" optional>
      The model to use for execution (e.g., "gpt-4", "claude-3-opus")
    </ParamField>

    <ParamField body="stream" type="boolean" optional>
      Whether to stream the response
    </ParamField>
  </Expandable>
</ParamField>

### Example Request

```json theme={null}
{
  "brxId": "brk-12345678-90ab-cdef-1234-567890abcdef",
  "schemaValues": {
    "variable": "example value"
  },
  "executionOptions": {
    "maxTokens": 1000,
    "temperature": 0.7,
    "topP": 0.9,
    "model": "gpt-4",
    "stream": false
  }
}
```

## Response

<ResponseField name="executeBrxResponse" type="object">
  <Expandable title="properties">
    <ResponseField name="httpResponse" type="object">
      <Expandable title="properties">
        <ResponseField name="isError" type="boolean">
          Indicates whether the request resulted in an error
        </ResponseField>

        <ResponseField name="statusMsg" type="string">
          A message describing the status of the request
        </ResponseField>

        <ResponseField name="result" type="string">
          The result of the BRK execution
        </ResponseField>

        <ResponseField name="executionId" type="string">
          The unique identifier for this execution
        </ResponseField>

        <ResponseField name="executionTime" type="number">
          The time taken to execute the BRK in milliseconds
        </ResponseField>

        <ResponseField name="tokenUsage" type="object">
          Token usage information for the execution

          <Expandable title="properties">
            <ResponseField name="prompt" type="number">
              Number of tokens in the prompt
            </ResponseField>

            <ResponseField name="completion" type="number">
              Number of tokens in the completion
            </ResponseField>

            <ResponseField name="total" type="number">
              Total number of tokens used
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

### Example Response

```json theme={null}
{
  "executeBrxResponse": {
    "httpResponse": {
      "isError": false,
      "statusMsg": "BRK executed successfully",
      "result": "This is the result of the BRK execution with the input value: example value",
      "executionId": "exec-12345678-90ab-cdef-1234-567890abcdef",
      "executionTime": 1234.56,
      "tokenUsage": {
        "prompt": 100,
        "completion": 50,
        "total": 150
      }
    }
  }
}
```

## Error Codes

<ResponseField name="400" type="object">
  Bad Request - The request was malformed or missing required parameters
</ResponseField>

<ResponseField name="401" type="object">
  Unauthorized - Authentication credentials are missing or invalid
</ResponseField>

<ResponseField name="403" type="object">
  Forbidden - The authenticated user does not have permission to execute the requested BRK
</ResponseField>

<ResponseField name="404" type="object">
  Not Found - The requested BRK does not exist
</ResponseField>

<ResponseField name="429" type="object">
  Too Many Requests - The user has exceeded the BRK execution rate limit
</ResponseField>

<ResponseField name="500" type="object">
  Internal Server Error - An unexpected error occurred on the server
</ResponseField>

## Notes

* The `schemaValues` object must match the schema of the BRK. You can use the [Get BRK Schema](/api-reference/endpoint/get) endpoint to retrieve the schema.
* The `executionOptions` object allows you to customize the execution behavior, such as the model to use and the sampling parameters.
* The response includes the result of the execution, as well as metadata such as the execution time and token usage.
* If the `stream` option is set to `true`, the response will be streamed as it is generated. This is useful for long-running executions.
* The `tokenUsage` object provides information about the number of tokens used in the prompt, completion, and total. This can be useful for monitoring usage and costs.
