# JavaScript & TypeScript

glim is plain HTTPS + JSON, so built-in `fetch` (Node 18+, Bun, Deno, browsers) is the whole integration. Add the x402 client if you want to pay per call from a wallet instead of an API key.

## With an API key

Create a key at `glim.sh/app` and send it as an `x-api-key` header (or `Authorization: Bearer`):

**fetch — API key**

```
const res = await fetch("https://glim.sh/api/v1/web/search", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.GLIM_API_KEY,
  },
  body: JSON.stringify({ query: "x402 protocol" }),
});
const data = await res.json();
```

## Pay per call with a wallet

`@x402/fetch` wraps `fetch` so a `402` response is paid automatically and retried — no account, no key. Fund the wallet with USDC on `Base`:

**install**

```
npm install @x402/fetch @x402/evm viem
```

**fetch — wallet pays on 402**

```
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
registerExactEvmScheme(client, {
  signer: privateKeyToAccount(process.env.EVM_PRIVATE_KEY),
});
const fetchWithPayment = wrapFetchWithPayment(fetch, client);

const res = await fetchWithPayment("https://glim.sh/api/v1/web/search", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ query: "x402 protocol" }),
});
const data = await res.json();
```

> **Set Content-Type explicitly** The payment wrapper rebuilds the request on retry, and a string body with no `Content-Type` defaults to `text/plain` — so always set `content-type: application/json` on POST bodies, as above.

## Every tool, same shape

Swap the path and body to reach any tool — `twitter/search`, `reddit/get`, `web/fetch`, `github/search`, and the rest. The [OpenAPI spec](https://glim.sh/openapi.json) carries typed schemas and a copy-pasteable example for each; the [API reference](https://glim.sh/docs-openapi) renders them in the browser.

---

## All docs pages


**Get started**

- [Introduction](https://glim.sh/docs.md?page=introduction)
- [MCP quickstart](https://glim.sh/docs.md?page=quickstart)
- [REST API quickstart](https://glim.sh/docs.md?page=quickstart-rest)
- [JavaScript quickstart](https://glim.sh/docs.md?page=quickstart-js)
- [Python quickstart](https://glim.sh/docs.md?page=quickstart-python)
- [Payments & auth](https://glim.sh/docs.md?page=payments)

**Tools**

- [Twitter / X](https://glim.sh/docs.md?page=twitter)
- [Reddit](https://glim.sh/docs.md?page=reddit)
- [Web](https://glim.sh/docs.md?page=web)
- [GitHub](https://glim.sh/docs.md?page=github)
- [Amazon](https://glim.sh/docs.md?page=amazon)
- [YouTube](https://glim.sh/docs.md?page=youtube)
- [Telegram](https://glim.sh/docs.md?page=telegram)

**Reference**

- [Changelog](https://glim.sh/docs.md?page=changelog)
- [API reference](https://glim.sh/docs-openapi)
- [OpenAPI spec](https://glim.sh/openapi.json)
