# cli: add `entire api` authenticated passthrough (core + cell)

`a7e9795`→[main](/content/gh/entireio/cli/commits/main/index.html)·  Soph·2w ago·4 files·+579 added/-0 removed

A `gh api`-style escape hatch: make an authenticated request to an Entire API and print the JSON response, with the CLI attaching the right bearer and dialing the right host.

## API Commands

- `entire api /api/v1/clusters` # control plane
- `entire api --to cell /api/v1/me/activity` # home entire-api cell
- `entire api --to cell "/api/v1/me/recap?repo={repo_id}"`

- `--to core (default)` reuses the same bearer resolution as `auth token` (honors `ENTIRE_TOKEN`, else the active context); `--to cell` mints the jurisdictional token via `NewEntireAPICellClient`. Data API is omitted deliberately — it's being retired.
- Placeholders filled from the origin remote: `{owner}`, `{repo}`, and `{repo_id}` (the repo's ULID, resolved from its mirror) — the last is what cell endpoints key on.
- Method defaults to `GET`, or `POST` when `-f/-F` fields or `--input` is given; `-X` overrides. `GET + fields` go on the query string. `-H` adds headers, `-i` prints status + headers, and JSON responses are pretty-printed.
- Adds `api.Client.Request` as the general method/header escape hatch behind it.

### Sessions

e7709d561284View transcript

## Changes

4

- cmd/entire/cli

---

```go
148 unmodified lines

return c.do(ctx, http.MethodDelete, path, nil, nil)
}

// Request sends an authenticated request with an explicit method, optional
// extra headers, and an optional raw body. It’s the general-purpose escape
// hatch behind `entire api`; prefer the typed verbs (Get/Post/…) for normal
// use. The bearer, User-Agent, and default Accept are still attached by the
// transport; a body still gets Content-Type: application/json.
func (c *Client) Request(ctx context.Context, method, path string, headers http.Header, body io.Reader) (*http.Response, error) {
return c.do(ctx, method, path, body, headers)
}

func (c *Client) do(ctx context.Context, method, path string, body io.Reader, headers http.Header) (*http.Response, error) {
endpoint, err := ResolveURLFromBase(c.baseURL, path)
if err != nil {
```

---

### Additional Code

```go
package cli

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"os"
	"sort"
	"strconv"
	"strings"

"github.com/spf13/cobra"
	"github.com/entireio/cli/cmd/entire/cli/api"
	"github.com/entireio/cli/cmd/entire/cli/auth"
	"github.com/entireio/cli/cmd/entire/cli/gitremote"
	"github.com/entireio/cli/internal/coreapi"
)

// Function Definitions
// ...
```

---

```go
const apiMaxResponseBytes = 32 << 20 // 32 MiB cap on a printed response body.

// Functions related to API handling, Context resolution, and request handling
// ...
```

---

```go
// Test functions
// ...
```
