# How to use the Attackfee agent SDK

`@attackfee/agent` is the client for automated callers. Version 0.1.0 in the repo. The package is not on a public package registry yet. From a clone, run `npm install` and `npm run build`, then install the package by path.

Every request sends `Attackfee-Client: agent`. When a write needs a pass, the client does the work and retries once. An automated client can instead pay the offer in an HTTP 402; that path is a separate example in the repo, not something the package does by itself.

```sh
# From a clone of this repo: npm install && npm run build
npm install /path/to/attackfee/packages/agent
```

```js
import { createAgent } from "@attackfee/agent";

const agent = createAgent({ base: "http://127.0.0.1:8787" });
const result = await agent.fetch("/contact", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ message: "hi" }),
});
```

`result.response` is the final response. `result.via` is `work` when the client did the work, and `none` when the first response was already final.

`solveWork`, also exported from this package, runs a challenge payload in Node. Browsers use `@attackfee/widget` instead.

For a WordPress site, set `issuer` to the site's `/wp-json/attackfee` origin. The [agent docs](/docs/agent) describe the routes the client calls. The hosted [demo](/demo) checks writes only.

## Where Attackfee fits

Use this when you are writing an automated client against a site that already has Attackfee on it. For the steps without a package, see [How agents write to an Attackfee site](/learn/agents/how-agents-write-to-an-attackfee-site).

- [Attackfee](/)
- [Learn](/learn)
- [Agents](/learn/agents)
- [How to use the Attackfee agent SDK](/learn/agents/agent-sdk)

## Related

- [Attackfee Learning Center](/learn)
- [How agents write to an Attackfee site](/learn/agents/how-agents-write-to-an-attackfee-site)
- [How the Attackfee MCP server works](/learn/agents/mcp-server)
- [Agent](/docs/agent)
- [Agent calls](/docs/ask)
- [Demo](/demo)

## Questions



### "Does the package pay a 402 offer by itself?"

"No. It does the work and retries once. A runnable payment example lives in the project's examples directory."

### "Is it on a public package registry?"

"No. Install it from a clone, after npm install and npm run build, by path."

### "How do I point it at WordPress?"

"Set issuer to the site's /wp-json/attackfee origin. The plugin is the issuer on that site."

### "What is result.via?"

"work when the client did the work and retried, and none when the first response was already final."

### "Should browsers use this package?"

"No. Browsers use the page script from @attackfee/widget."
