# Read API

The Read API is an HTTP API for reading Harnessforce projects, issues, sessions, traces, logs, and metrics. Send your API token as a Bearer token.

```sh
/plugin marketplace add lambda-script/harnessforce-agent
/plugin install harnessforce@harnessforce-agent
/harnessforce:setup
```

The Read API is an HTTP API for reading Harnessforce data such as projects, issues, sessions, traces, logs, and metrics from your own tools. The base URL is `https://harnessforce.dev/api/v1`. Authenticate by sending the API token issued when you sign in with `harnessforce login` in an `Authorization: Bearer` header.

## Authentication

* API tokens are issued when you sign in with `harnessforce login` or through the MCP server's OAuth sign-in.
* Each API token is tied to one workspace and role, and can't read or write beyond that role's permissions. The role is checked on every request.
* Access tokens expire 1 hour after they're issued. Requests with an expired token fail with `unauthorized` (401). Get a new access token with your refresh token, then retry.
* Ingest keys can't be used with the Read API.

## Minimal example

Search for issues whose identifier or title contains `ENG-42`:

List responses have this shape. When there's nothing more to fetch, `next_cursor` is `null`.

```json
{
  "items": [{ "identifier": "ENG-42", "title": "..." }],
  "next_cursor": null
}
```

With `query`, an issue whose identifier exactly matches the query comes first, and the rest are sorted by identifier.

## Resources

| Path                                  | Returns                                                                                                                                                             |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GET /projects`, `/projects/{id}`     | Projects and progress                                                                                                                                               |
| `GET /issues`, `/issues/{identifier}` | Issues and links                                                                                                                                                    |
| `GET /runs`, `/runs/{id}`             | Sessions and their metrics                                                                                                                                          |
| `GET /traces/{traceId}`               | The spans in a trace                                                                                                                                                |
| `GET /logs`                           | Logs matching your filters                                                                                                                                          |
| `GET /metrics`                        | Metric time series                                                                                                                                                  |
| `GET /evaluations`                    | Evaluations                                                                                                                                                         |
| `GET /repositories`                   | Repositories synced through the GitHub App and assigned to a project                                                                                                |
| `GET /workspace`                      | Workspace settings (how many days of past sessions you can import, and which content categories the workspace stores, who can read them and how long they are kept) |
| `GET /onboarding`                     | The setup steps shown to you, whether each is done, and the URL of each step's screen (used by `harnessforce status`)                                               |
| `GET /analysis`                       | Analysis results, aggregated per project                                                                                                                            |

Issue links with a confidence of 0 aren't returned. Each session includes `status` (`running`, `completed`, or `error`), model, token counts, `cost_usd` and whether it's estimated (`cost_estimated`), API and tool counts, repository, branch, and linked issues. Values that can't be determined are `null`. Sessions don't include the user.

The API also accepts the two writes the MCP server uses: registering a session and completing a session. They use the same authentication.

## Conventions

* Times are returned in ISO 8601 with an offset. Date-time input without an offset is rejected with 400.
* Response field names use snake\_case.
* Undefined query parameters, or the same query parameter repeated, are rejected with `invalid_request`.
* Every response carries `Cache-Control: private, no-store`.
* Prompt and response content is returned only when the workspace has turned on content storage and the caller is one of the people who can read content for that row. A new workspace lets everyone read it, so a Member's or Viewer's request also returns content from other members' rows. When the workspace limits reading to Owners, Admins, and the sender, Owners and Admins can read other people's content and the sender can read only their own rows.
* Write requests with a body larger than 4 MiB are rejected with `invalid_request`.

## Pagination

Lists are paginated with a cursor. To get the next page, pass the previous page's `next_cursor` as `cursor`. `limit` defaults to 50 and can be up to 100. `/traces/{traceId}` and `/metrics` return everything in one response.

| List             | Sort order            | Filters                                                          |
| ---------------- | --------------------- | ---------------------------------------------------------------- |
| projects, issues | Newest created first  | For issues: `project`, `status_category`, `assignee`, `query`    |
| sessions         | Newest started first  | `issue`, `from`, `to`                                            |
| logs             | Newest occurred first | `issue`, `from`, `to`                                            |
| evaluations      | Newest recorded first | `project`, `issue`, `repository`, `kind`, `result`, `from`, `to` |

For issues, `assignee` filters by the GitHub assignee. Pass the member's email address for an assignee linked to a member, `gh:<login>` for one that isn't, and `none` for issues with no assignee.

`from` and `to` are ISO 8601 with an offset, and cover `from` up to but not including `to`. Filtering by a project or issue that doesn't exist returns an empty `items` list instead of `not_found`.

## Metric time series

`GET /metrics` aggregates metric data points into intervals.

| Query parameter | Required | Meaning                                |
| --------------- | -------- | -------------------------------------- |
| `name`          | ✓        | Metric names, 1 to 10, comma-separated |
| `from`, `to`    | ✓        | ISO 8601 with an offset                |
| `granularity`   | ✓        | One of `1m`, `15m`, `1h`, or `1d`      |
| `project`       | —        | A project key                          |
| `issue`         | —        | An issue identifier                    |

A request can cover up to 1,440 intervals. Intervals with no data points are left out of `points`, so they can't be mistaken for zero. With `1d`, intervals start at 00:00 in the workspace's time zone.

## Errors

Errors return an HTTP status and a body of `{"code": ..., "message": ...}`.

| `code`                       | HTTP status | When                                                                                                                                                                                                        |
| ---------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `invalid_request`            | 400         | The input is malformed or breaks a constraint                                                                                                                                                               |
| `unauthorized`               | 401         | The token is missing, invalid, revoked, or expired                                                                                                                                                          |
| `forbidden`                  | 403         | The role lacks permission, or the write targets a read-only workspace                                                                                                                                       |
| `not_found`                  | 404         | The target doesn't exist, including targets outside the token's workspace                                                                                                                                   |
| `invalid_workspace_timezone` | 409         | The server can't resolve the workspace timezone, so a request split by calendar day (`granularity=1d`) can't be answered. It continues until an Owner or Admin fixes the timezone in the workspace settings |
| `conflict`                   | 409         | The write conflicts with the target's current state                                                                                                                                                         |
| `rate_limited`               | 429         | You've hit the rate limit. Includes `Retry-After`                                                                                                                                                           |
| `internal`                   | 500         | An internal server error                                                                                                                                                                                    |
| `unavailable`                | 503         | A dependency can't be reached. Includes `Retry-After`                                                                                                                                                       |

## Rate limits

Each API token can make up to 600 reads and 60 writes per fixed 1-minute window. The limit is the same on every plan. Requests over the limit get `rate_limited` and a `Retry-After` header with the seconds left in the window.

## MCP server

The same host serves the MCP server at `/mcp`. Authentication, OAuth, rate limits, and error codes are the same as the Read API; the tools and their inputs differ. You choose one workspace and one project on the sign-in screen.

## Compatibility

`/api/v1` stays backward compatible. Breaking changes ship as `/api/v2`, and `/api/v1` is maintained for at least 12 months.

## Read next

* [Sessions](/en/docs/concepts/session): What session fields mean
* [Linking sessions to issues](/en/docs/concepts/issue-linking): Link confidence
* [Semantic conventions](/en/docs/semantic-conventions): Telemetry attributes
