# Azure API Management CLI Overview

The `hiddenlayer-apim` CLI deploys HiddenLayer policy fragments to Azure API Management (APIM) and applies those fragments to APIs that proxy LLM traffic. Use the CLI when you want a repeatable way to add Runtime Security guardrails without hand-editing large APIM policy XML blocks.

The CLI can protect requests before they reach the model, responses before they return to users, or both. It supports package-based deployment so you can choose the evaluation flow that matches your architecture.

Deploy `v2-request-evals` for inbound-only protection, `v2-response-evals` for outbound-only protection, or both packages for full request and response guardrails.

## How It Works

1. `hiddenlayer-apim deploy` creates HiddenLayer named values and policy fragments in your APIM instance.
2. `hiddenlayer-apim apply <api-id>` reads the target API policy and injects `<include-fragment>` references.
3. APIM calls HiddenLayer evaluation endpoints during inbound and/or outbound processing.
4. HiddenLayer returns a provider-shaped payload. APIM forwards the payload, redacted payload, or block response based on the policy decision.


```mermaid
flowchart LR
    clientApp["Client Application"] --> apim["Azure API Management"]
    apim --> requestEval["Request Evaluation"]
    requestEval -->|"allow or redact"| llmBackend["LLM Backend"]
    requestEval -->|"block"| blockedResponse["Block Response"]
    llmBackend --> responseEval["Response Evaluation"]
    responseEval --> clientApp
```

## Fragment Packages

| Package | Endpoint | APIM stage | Use case |
|  --- | --- | --- | --- |
| `v2-request-evals` | `POST /detection/v2/request-evaluations` | Inbound | Evaluate and optionally block or redact prompts before APIM forwards them to the model. |
| `v2-response-evals` | `POST /detection/v2/response-evaluations` | Outbound | Evaluate and optionally block or redact model responses before returning them to users. |
| `v1-interactions` | `POST /detection/v1/interactions` | Inbound and outbound | Legacy structured interaction integration. |


Recommended path
Use the v2 packages for new APIM guardrails deployments. The v2 endpoints accept provider-native payloads and return provider-shaped payloads, which keeps the APIM policy simpler.

## Provider Compatibility

Provider support depends on which package you deploy:

- **`v2-request-evals` and `v2-response-evals`** forward the original provider request and response bodies to HiddenLayer's v2 evaluation APIs and use whatever HiddenLayer returns. The APIM fragments do not parse provider-specific fields. Provider support is therefore whatever HiddenLayer's `/detection/v2/request-evaluations` and `/detection/v2/response-evaluations` endpoints accept (OpenAI, Azure OpenAI, Anthropic Messages, and additional providers as they are added). Use the `HL-Provider-Id` request header to override auto-detection and `HL-Runtime-Edge-Provider` to label the edge integration.
- **`v1-interactions`** is OpenAI chat-completions shaped. It reads OpenAI request fields (`model`, `messages`) and OpenAI response fields (`choices[].message`), and its block response is an OpenAI chat-completion payload. Use it for Azure OpenAI / OpenAI chat-completions APIs.


See [Fragment packages](/docs/integrations/azure_apim/cli_fragment_packages#provider-compatibility) for the full per-package breakdown.

## Related Pages

- [Install the CLI](/docs/integrations/azure_apim/cli_install)
- [Configure the CLI](/docs/integrations/azure_apim/cli_configuration)
- [CLI commands](/docs/integrations/azure_apim/cli_commands)
- [Fragment packages](/docs/integrations/azure_apim/cli_fragment_packages)
- [Usage examples](/docs/integrations/azure_apim/cli_usage_examples)
- [Troubleshooting](/docs/integrations/azure_apim/cli_troubleshooting)