> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gravixlayer.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Host URL

> Get a public HTTPS URL to access a runtime port

Open (or refresh) a web service on `*.service.gravixlayer.ai` for a guest HTTP port.

`POST /v1/agents/runtime/{runtime_id}/services`

<Note>
  Prefer [Web Services](/documentation/agentruntime/getting-started/web-services) for full access-model details (private token vs `--public`, TTL, revoke). The guest process must already be listening on the port.
</Note>

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import time

  from gravixlayer import GravixLayer

  client = GravixLayer()  # defaults to cloud="aws", region="us-east-1"
  sandbox = client.runtime.create()  # defaults to template="base-small"

  sandbox.run_cmd(
      command="sh",
      args=["-lc", "nohup python -m http.server 8080 --bind 0.0.0.0 >/tmp/http.log 2>&1 &"],
  )
  time.sleep(1)

  with sandbox.service(port=8080) as svc:
      print(svc.web_url)
      print(svc.browser_url)
      if svc.token:
          print("token:", svc.token[:8] + "…")

  sandbox.kill()
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { GravixLayer } from 'gravixlayer';

  const client = new GravixLayer(); // defaults to cloud="aws", region="us-east-1"
  const sandbox = await client.runtime.create(); // defaults to template="base-small"

  await sandbox.runCmd('sh', {
    args: ['-lc', 'nohup python -m http.server 8080 --bind 0.0.0.0 >/tmp/http.log 2>&1 &'],
  });
  await new Promise((resolve) => setTimeout(resolve, 1000));

  const svc = await sandbox.service(8080);
  console.log(svc.url);
  console.log(svc.service.browserUrl);
  if (svc.service.token) {
    console.log('token:', `${svc.service.token.slice(0, 8)}…`);
  }

  await sandbox.kill();
  ```

  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  # Requires: GRAVIXLAYER_API_KEY, jq
  # Guest must already listen on the port before opening the service.

  RT=$(gravixlayer runtime create --wait --output json | jq -r '.runtime_id')

  gravixlayer runtime service web-url "$RT" 8080 --expires-in 3600 --output json

  # Optional: --public  (unauthenticated access)
  # Optional: --rotate-token

  gravixlayer runtime kill "$RT" -y
  ```

  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  # Requires: GRAVIXLAYER_API_KEY, jq
  API="https://api.gravixlayer.ai/v1"
  AUTH=(-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" -H "Content-Type: application/json")

  RT=$(curl -sS -X POST "$API/agents/runtime" "${AUTH[@]}" \
    -d '{"template":"base-small","cloud":"aws","region":"us-east-1"}' | jq -r '.runtime_id')

  for i in $(seq 1 60); do
    STATUS=$(curl -sS "$API/agents/runtime/$RT" -H "Authorization: Bearer $GRAVIXLAYER_API_KEY" | jq -r '.status')
    [ "$STATUS" = "running" ] && break
    sleep 2
  done

  curl -sS -X POST "$API/agents/runtime/$RT/services" "${AUTH[@]}" \
    -d '{
      "port": 8080,
      "expires_in_seconds": 3600,
      "is_public": false,
      "rotate_token": false
    }'
  echo

  curl -sS -X DELETE "$API/agents/runtime/$RT" \
    -H "Authorization: Bearer $GRAVIXLAYER_API_KEY"
  echo
  ```
</CodeGroup>

## Parameters

| Parameter            | Type    | Required | Description                                    |
| -------------------- | ------- | -------- | ---------------------------------------------- |
| `runtime_id`         | string  | Yes      | Runtime identifier                             |
| `port`               | integer | Yes      | Guest HTTP port to expose                      |
| `expires_in_seconds` | integer | No       | TTL in seconds (default `3600`, max `86400`)   |
| `is_public`          | boolean | No       | Allow unauthenticated access (default `false`) |
| `rotate_token`       | boolean | No       | Mint a new private token                       |

## Response

| Field             | Type    | Description                                                    |
| ----------------- | ------- | -------------------------------------------------------------- |
| `url` / `web_url` | string  | Public HTTPS URL for the port                                  |
| `browser_url`     | string  | Browser-friendly URL (cookie auth for private services)        |
| `token`           | string  | Service token (returned once on open/rotate; private services) |
| `expires_at`      | string  | Expiry timestamp                                               |
| `is_public`       | boolean | Whether the service is public                                  |

## Common Ports

| Port   | Use Case             |
| ------ | -------------------- |
| `3000` | Node.js / React apps |
| `5000` | Flask                |
| `8000` | Django / FastAPI     |
| `8080` | Generic HTTP         |
| `8888` | Jupyter              |
