# API

Monarch build services leverage the [monarch-c2-sdk](https://test.pypi.org/project/monarch-c2-sdk/) python package for handling build requests. Under the hood, a build service is a simple HTTP server that handles post requests from the build client that comes pre-installed in monarch builder containers.

Each request is automatically reformatted into a `BuildRequest` object, predefined by the monarch package, that contains the build parameters as a dictionary of values.

```python
class BuildRequest:
    def __init__(self, params: dict):
        """
        An object representing a build request received from the main C2 server.
        :param params: a dictionary of build parameters.
        """
        self.params = params
```

After this, a registered callback, **your** build routine, is called with the `BuildRequest` passed as a parameter. Your callback is expected to return a `BuildResponse` object, which tells Monarch's build client whether build was successful, if any errors were reported, and if none, the actual binary that was built.

```python
class BuildResponse:
    def __init__(self, status: int, error: str, build: str):
        """
        An object representing a response to a build request received from the main C2 server.
        A build would typically end with a status (STATUS_SUCCESS | STATUS_ERROR), an error message (if applicable),
        and the binary or file produced by the build.
        :param status: build status, either STATUS_SUCCESS or STATUS_ERROR
        :param error: build error message, if any
        :param build: the build file. If multiple files are produced, then return an archive.
        """
        self.status = status
        self.error = error
        self.build = build
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://monarch.gitbook.io/monarch/integration/builder/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
