TypeScript SDK integration
On this page
Use the Unfenced SDK when your application needs web content without an MCP client. It is a typed HTTP client; Unfenced runs the browser and returns the extracted document.
Install and authenticate
Sign in to Unfenced to create your agent’s API key and make it available as UNFENCED_TOKEN in your application's environment. Use a Node.js version supported by the SDK package.
Set UNFENCED_TOKEN in your terminal
Read your Unfenced key privately, then start your client from this same terminal. These variables last for the current terminal session. An app opened from the desktop may not inherit them.
Bash or Zsh
read -r -s UNFENCED_TOKEN
export UNFENCED_TOKENPowerShell 7.1 or later
$env:UNFENCED_TOKEN = Read-Host -MaskInput "Unfenced API key"npm install @unfenced-ai/sdkFetch your first page
Run this in a TypeScript project with an ESM-compatible runner or compile it before execution:
import { Unfenced } from "@unfenced-ai/sdk";
const apiKey = process.env.UNFENCED_TOKEN;
if (!apiKey) throw new Error("Set UNFENCED_TOKEN before starting");
const unfenced = new Unfenced({
baseUrl: "https://unfenced.ai/api",
apiKey,
});
const result = await unfenced.fetch("https://example.com");
if (result.outcome === "delivered") {
console.log(result.doc.markdown);
} else {
console.log(result);
}A delivered result should contain the Example Domain text. Fetch results use outcome; they do not have an ok flag. Handle offered and failed results explicitly in your application rather than treating every reply as a document.
Keep the key on your server
An environment variable keeps the key out of source code. Keep it out of browser bundles too: call Unfenced from your server, and send only the resulting content to your frontend.
If a request fails
- Unauthorized: verify the key and use the API base URL ending in
/api. - No Markdown: inspect
outcomebefore readingdoc. - Delivered text looks like a login page: inspect content-confidence warnings and use the authenticated-page recipe.
- A source refuses access: check the failure reference before retrying.
What to build next
Prepare web pages for RAG or research multiple URLs. The SDK README and API reference cover additional methods.
Configuration reviewed: 2026-10-04. Check the connection in your client before relying on it.