> For the complete documentation index, see [llms.txt](https://monarch.gitbook.io/monarch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monarch.gitbook.io/monarch/integration/builder/api.md).

# 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
```
