# Declarative API
URL: https://docs.datarobot.com/en/docs/api/code-first-tools/declarative-api.html

> Use the declarative API as a way to programatically provision DataRobot entities.

# Declarative API

DataRobot offers a Terraform-native declarative API used to programmatically provision DataRobot entities such as models, deployments, applications, and more. The declarative API allows you to:

1. Specify the desired end state of infrastructure, simplifying management and enhancing adaptability across cloud providers.
2. Automate provisioning to ensure consistency across environments and remove concerns about execution order.
3. Simplify version control.
4. Use application templates to reduce workflow duplication and ensure consistency.
5. Integrate with DevOps and CI/CD to ensure predictable, consistent infrastructure and reduce deployment risks.

DataRobot recommends using the declarative API as a code-first method to provision DataRobot resources end-to-end in a way that is both repeatable and scalable.

## Declarative API services

DataRobot has two services for using the declarative API: Pulumi and Terraform. DataRobot recommends using the service that supports your engineering needs. Pulumi is based on Python, while Terraform is based on yaml. Note that application templates are configured for Pulumi by default.

For information on using Pulumi for your declarative API needs, access the [Pulumi registry](https://www.pulumi.com/registry/packages/datarobot/) and review the [installation guide](https://github.com/datarobot-community/pulumi-datarobot?tab=readme-ov-file#datarobot-resource-provider).

For information on using Terraform, access the [Terraform registry](https://registry.terraform.io/providers/datarobot-community/datarobot/latest) and review the [installation guide](https://github.com/datarobot-community/terraform-provider-datarobot).

Review an example below of how you can use the declarative API to provision DataRobot resources using the Pulumi CLI:

```
import pulumi_datarobot as datarobot
import pulumi
import os

for var in [
    "OPENAI_API_KEY",
    "OPENAI_API_BASE",
    "OPENAI_API_DEPLOYMENT_ID",
    "OPENAI_API_VERSION",
]:
    assert var in os.environ

pe = datarobot.PredictionEnvironment(
    "pulumi_serverless_env", platform="datarobotServerless"
)

credential = datarobot.ApiTokenCredential(
    "pulumi_credential", api_token=os.environ["OPENAI_API_KEY"]
)

cm = datarobot.CustomModel(
    "pulumi_custom_model",
    base_environment_id="65f9b27eab986d30d4c64268",  # GenAI 3.11 w/ moderations
    folder_path="model/",
    runtime_parameter_values=[
        {"key": "OPENAI_API_KEY", "type": "credential", "value": credential.id},
        {
            "key": "OPENAI_API_BASE",
            "type": "string",
            "value": os.environ["OPENAI_API_BASE"],
        },
        {
            "key": "OPENAI_API_DEPLOYMENT_ID",
            "type": "string",
            "value": os.environ["OPENAI_API_DEPLOYMENT_ID"],
        },
        {
            "key": "OPENAI_API_VERSION",
            "type": "string",
            "value": os.environ["OPENAI_API_VERSION"],
        },
    ],
    target_name="resultText",
    target_type="TextGeneration",
)

rm = datarobot.RegisteredModel(
    resource_name="pulumi_registered_model",
    name=None,
    custom_model_version_id=cm.version_id,
)

d = datarobot.Deployment(
    "pulumi_deployment",
    label="pulumi_deployment",
    prediction_environment_id=pe.id,
    registered_model_version_id=rm.version_id,
)

pulumi.export("deployment_id", d.id)
```

---
