> For the complete documentation index, see [llms.txt](https://docs.cortex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortex.io/streamline/plugins/calling-internal-service-endpoints-via-plugin-proxy.md).

# Calling internal service endpoints via plugin proxy

Your organization may have services that are not publicly accessible but contain information that would be useful to manage in Cortex. You can set up a plugin proxy that works with [Cortex's Axon Relay](/ingesting-data-into-cortex/integrations/axon-relay.md) to call internal services without exposing the service or authentication outside of your firewall.

## How to call internal service endpoints in a plugin proxy

### Prerequisites

Before getting started:

* You should have already [set up the Cortex Axon agent](/ingesting-data-into-cortex/integrations/axon-relay.md) and [set your Cortex API token in the .env file](https://docs.cortex.io/streamline/plugins/pages/pnGfouIb4trWTpFzEjTd#step-1.2-create-a-.env-file-and-a-docker-compose.yml-file).
* You should have already followed the steps to [create a plugin](/streamline/plugins/creating-plugins.md) and a [plugin proxy](/streamline/plugins/creating-plugins/plugin-proxy.md).

#### Considerations

* This guide describes using a Docker compose file, but note that Axon Relay can be run in Kubernetes or other container systems.
* As an example throughout this guide, assume a service in the network has the following endpoint:

`GET http://cities.internal.my-company.com/api/cities/s => ["Seattle", "Sydney", "Shanghai" ...]`

### Step 1: Create request forwarding configuration

* Create a file that defines how requests are routed.
  * The example below permits any requests, but note that the `method` and `path` can be narrowed to allow access to specific endpoints:

```json
{
   "private": [
     {
       "method": "any", 
       "path": "/*",   
       "origin": "http://cities.internal.my-company.com"
     }
   ]
}

```

In your configuration, you will enter the root of your service URL as the value of `origin`.

### Step 2: Configure Axon Docker container

1. Create the Axon container (in this example, via Docker Compose for brevity) that defines how the container will route traffic and which routes are allowed.
   * For production employments, two replicas should be specified, and the instances should be run in Kubernetes or some other durable system.. The example below can be used to test the configuration and can be run locally.

```yaml
services:
 relay-cities:
   image: ghcr.io/cortexapps/cortex-axon-agent:latest
   environment:
     HOSTNAME: relay-cities-${HOSTNAME:-local}
     CORTEX_API_TOKEN: $CORTEX_API_TOKEN
   volumes:
     - "./accept.cities.json:/app/accept.json"
   command: [
     "relay",
     "-a", "axon-relay-cities", # this can be any unique value
     "-f", "/app/accept.json",
   ]

```

2. Start the container, which will register it with Cortex: Run the command `docker compose up`.\\

### Step 3: Include the Axon call in your plugin proxy code

Your endpoints can be invoked by specifying a URL in the format: `http://[your-configuration-alias]@relay-proxy.cortex.io[/desired/url/path]`

For the example above, we could create a helper function to fetch cities by prefix:

```javascript
import from "@cortexapps/plugin-core";

const getCitiesByLetter = async (prefix: string) => { 
  const result = await fetch(`http://axon-relay-cities@relay-proxy.cortex.io/api/cities?prefix=${prefix}`); 
  return result.json(); 
};
```
