# Creating a plugin proxy

To access authenticated external APIs with your plugin, you can configure a plugin proxy.

Plugin proxies try to match incoming requests against configured URL prefixes and apply rules to those requests (such as adding headers) before propagating the request to the specified downstream URL. Header rules have access to secrets via Mustache-like templating for easy authentication.

Plugin proxies must be explicitly associated with a particular plugin in the plugin configuration; once specified, all proxyFetch requests made by that plugin will use the proxy. If no proxy is defined for a plugin, no special logic will apply and requests will be propagated to downstream URLs without modification.

### Considerations

When creating a plugin proxy, consider the following:

* If there are multiple matching URL prefixes with overlapping header keys, the more specific (i.e. longer) prefix rules will be used.
* If a request from the plugin is invoked with header keys that overlap the proxy ruleset, the request-specific header values will be used.

## Creating a plugin proxy

Users with the `Edit Plugin Proxies` permission can create a plugin proxy.

{% hint style="info" %}
If you are using a proxy with sensitive information, such as an access token, first follow the [steps to create a secret](/configure/settings/api-keys/secrets.md) for the proxy.
{% endhint %}

1. From the main sidebar, select **Plugins**.
2. In the upper-right corner, click **Create proxy**.
3. Do the following:
   * Under **Proxy name**, enter a human-readable name for the proxy (required).
   * Under **Path**, enter a unique identifier made of letters, numbers, and/or hyphens for the proxy (required).
   * In the **URL prefixes** section, click **Add URL** to configure URL prefixes to apply rules to requests going through this proxy (required). All requests passing through this proxy that match the URL prefix will have a set of rules applied.
     * Optionally, click **Add header** to configure a header for the URL.
       * If you are using a proxy with sensitive information, you can use mustache templating to reference a global secret by tag, e.g. `{{secrets.my_auth_token}}`.
4. Click **Create proxy**.

### Example plugin proxy configuration

```json
{
  "id": "22",
  "tag": "github",
  "urlConfigurations": {
    "https://api.github.com": {
      "headers": [
        { "key": "X-GitHub-API-Version", "value": "2022-11-28" },
        { "key": "Authorization", "value": "Bearer {{ secrets.github_read_token }}" }
      ]
    }
  }
}
```

#### Example plugin code

```ts
import { CortexApi } from "@cortexapps/plugin-core";

const getGithubReleases = async (ownerName: string, repoName: string) => {
  const githubReleases = await fetch(`https://api.github.com/repo/${ownerName}/${repoName}/releases`);
  return githubReleases.json();
};
```

In this scenario, the request to fetch GitHub requests will be sent with the `X-GitHub-API-Version` and `Authorization` headers, with the `Authorization` header value interpolated to include the `github_read_token` secret if it exists in your Cortex workspace.

## Managing plugin proxies

You can view your plugin proxies in **Plugins** **> Proxies**.

<div align="left" data-with-frame="true"><figure><img src="/files/RYAkBXturE8mAlV9jj1r" alt="The &#x27;Proxies&#x27; tab shows all available plugin proxies." width="563"><figcaption></figcaption></figure></div>

### Editing a plugin proxy

Users with the `Edit Plugin Proxies` permission can edit a plugin proxy.

1. From the main sidebar, select **Plugins**.
2. Select the **Proxies** tab.
3. Locate the proxy you want to edit, then click the **Overflow menu**.
4. Select **Edit proxy**.
5. Make your changes, then click **Save proxy**.

### Deleting a plugin proxy

Users with the `Edit Plugin Proxies` permission can delete a plugin proxy.

Cortex does the following when a plugin proxy is deleted: checks if the proxy exists and if it's in use, deletes all headers for the proxy's URLs, flushes the header repo, deletes all URL configurations, removes any secret usages, and finally deletes the proxy entity itself.

1. From the main sidebar, select **Plugins**.
2. Select the **Proxies** tab.
3. Locate the proxy you want to delete, then click the **Overflow menu**.
4. Select **Delete proxy**.\
   The **Confirm proxy deletion** window opens.
5. Click **Delete**.


---

# 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://docs.cortex.io/streamline/plugins/creating-plugins/plugin-proxy.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.
