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

# Everest SDK

> Compress context before it reaches your AI agent.

Compression will remove unnecessary context and leave the important details.

For example, a coding agent makes calls to read files, execute code, and run tests. The file output, code results, and test logs might have a lot of noise. Pass the code, logs and other output to `compress` which will return only the content for the agent to focus on.

## Install

```bash theme={null}
npm install @everestagi/sdk
```

Requires Node.js 18 or later. ESM and CommonJS are supported, and the package has no runtime dependencies.

## Usage

```ts theme={null}
// Keep EVEREST_API_KEY on the server, out of client code and tool environments.
import { EverestClient } from '@everestagi/sdk'

const everest = new EverestClient({
  apiKey: process.env.EVEREST_API_KEY!,
  downstreamInputUsdPerMillionTokens: 4,
})

export async function compressOutput(output: string, goal: string) {
  const result = await everest.compress({ output, goal })

  console.log({
    applied: result.applied,
    reason: result.reason,
    tokensSavedEstimate: result.usage.tokensSavedEstimate,
    reductionRatio: result.usage.reductionRatio,
    inputCostSavedEstimateUsd: result.cost?.inputCostSavedEstimateUsd,
    requestId: result.request_id,
  })

  return result.text
}
```

`output` is the completed tool output; `goal` is the agent's overall task; `focus` is optional, output-specific guidance about what to preserve; and `command` is optional context only and is never executed. Skips, timeouts and API failures keep the original text. The SDK never runs or reruns tools.

You can optionally pass `focus`, `command` and `signal` to `compress`, or set `timeoutMs` when creating the client. `result.usage` contains local size, token and latency estimates. If you provide `downstreamInputUsdPerMillionTokens`, `result.cost` also estimates downstream input cost savings. These are estimates, not billing records.

## Savings estimates

Pass a local `sessionId` to compression calls, then use `getSavingsTotals(sessionId)` for that session or `getSavingsTotals()` for the client-wide total. To include expected cached reuse, configure `downstreamCachedInputUsdPerMillionTokens` and pass `estimatedCacheReadCount`; the SDK reports uncached, cached and combined estimated savings. Session IDs and cache-read estimates are not sent to Everest.

`request_id`, `timestamp`, `attempts` and other bounded diagnostics may be present when the API supplies them. Their absence does not make a valid compression result fail.

## Error-handling behavior

When `result.applied` is false, `result.text` is the exact original output. Stable SDK failure reasons include `sdk_authentication_failed`, `sdk_payload_too_large`, `sdk_timeout`, `sdk_cancelled`, `sdk_network_error`, `sdk_api_error` and `sdk_invalid_response`. API skip reasons include `below_threshold` and `raw_requested`.

Keep `EVEREST_API_KEY` only on your trusted server. Do not put it in browser code, mobile apps, distributed CLIs, agent tool environments, source control or logs.

Using Everest directly with Codex instead of integrating a product? See the [CLI guide](/cli).
