@openstatus/health-anthropic 0.1.4-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @openstatus/health-anthropic
2
+
3
+ [Anthropic](https://www.anthropic.com/) probe for
4
+ [`@openstatus/health`](https://jsr.io/@openstatus/health). Sends
5
+ `GET {baseUrl}/v1/models` with your API key in the `x-api-key` header, so it
6
+ proves both that the API answers and that the key is valid — with `fetch`
7
+ alone, on every runtime, and without spending a single token.
8
+
9
+ ```sh
10
+ deno add jsr:@openstatus/health jsr:@openstatus/health-anthropic
11
+ npm install @openstatus/health @openstatus/health-anthropic
12
+ ```
13
+
14
+ ```ts
15
+ import { createHealthHandler, readEnv } from "@openstatus/health";
16
+ import { anthropicProbe } from "@openstatus/health-anthropic";
17
+
18
+ const apiKey = readEnv("ANTHROPIC_API_KEY");
19
+
20
+ Deno.serve(
21
+ createHealthHandler({
22
+ probes: [
23
+ // the factory validates `apiKey` at construction, so pass a
24
+ // placeholder and let `skip` keep the unconfigured check from running.
25
+ anthropicProbe({
26
+ apiKey: apiKey || "unconfigured",
27
+ skip: () => !apiKey,
28
+ }),
29
+ ],
30
+ }),
31
+ );
32
+ ```
33
+
34
+ `apiKey` is the `sk-ant-…` key from the Anthropic Console. Listing models is a
35
+ free read with no side effects, so the probe can run on every health request.
36
+ The request also sends `anthropic-version: 2023-06-01`, the header every API
37
+ call requires; `anthropicDefaultVersion` exports it. `baseUrl` defaults to
38
+ `https://api.anthropic.com` and takes the origin of a gateway in front of it.
39
+ Like every probe here, this one never reads the environment itself — pass the
40
+ values in, and use `skip` for environments where Anthropic is not configured.
41
+
42
+ A 2xx here means the API is up and the key authenticates. It does not prove
43
+ that a specific model is available or that messages are within their rate
44
+ limit; a model-level outage shows up in your request errors before it shows up
45
+ here.
46
+
47
+ ```ts
48
+ anthropicProbe({
49
+ apiKey: apiKey || "unconfigured",
50
+ // optional overrides from the Probe contract
51
+ name: "llm",
52
+ critical: true,
53
+ timeoutMs: 2000,
54
+ skip: () => !apiKey,
55
+ });
56
+ ```
57
+
58
+ Non-critical by default: most services can answer without a model call, so an
59
+ outage degrades the report instead of taking the service out of rotation. Set
60
+ `critical: true` for a service whose every request is an inference.
61
+
62
+ ## About openstatus
63
+
64
+ [openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
65
+ and status page platform. This package is part of
66
+ [`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
67
+ endpoints behind openstatus's own services, extracted so any JavaScript server
68
+ can expose one. Point an
69
+ [openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
70
+ at the endpoint and assert on `status` in the body to be alerted on
71
+ `degraded` before it becomes `unhealthy`.
72
+
73
+ Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
74
+ Issues and PRs welcome.
75
+
76
+ ## License
77
+
78
+ [MIT](https://github.com/openstatusHQ/health/blob/main/LICENSE)
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
package/dist/mod.cjs ADDED
@@ -0,0 +1,42 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const __openstatus_health = require_rolldown_runtime.__toESM(require("@openstatus/health"));
3
+
4
+ //#region src/mod.ts
5
+ /** API base URL when `baseUrl` is unset. */
6
+ const anthropicDefaultBaseUrl = "https://api.anthropic.com";
7
+ /** Probe name when `name` is unset. */
8
+ const anthropicDefaultName = "anthropic";
9
+ /** The `anthropic-version` header sent with the request. */
10
+ const anthropicDefaultVersion = "2023-06-01";
11
+ /** A probe that expects 2xx from `GET {baseUrl}/v1/models` with `apiKey` in the `x-api-key` header; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey` or an invalid `baseUrl`. */
12
+ function anthropicProbe(options) {
13
+ const doFetch = options.fetch ?? globalThis.fetch;
14
+ const url = (0, __openstatus_health.probeUrl)({
15
+ probe: "anthropicProbe",
16
+ field: "baseUrl",
17
+ value: options.baseUrl ?? anthropicDefaultBaseUrl,
18
+ path: "/v1/models"
19
+ });
20
+ if (typeof options.apiKey !== "string" || options.apiKey.length === 0) throw new __openstatus_health.ProbeConfigError("anthropicProbe", "apiKey", typeof options.apiKey !== "string" ? `must be a string, got ${String(options.apiKey)}` : "must not be empty");
21
+ const headers = {
22
+ "x-api-key": options.apiKey,
23
+ "anthropic-version": anthropicDefaultVersion
24
+ };
25
+ return {
26
+ name: options.name ?? anthropicDefaultName,
27
+ critical: options.critical ?? false,
28
+ timeoutMs: options.timeoutMs,
29
+ skip: options.skip,
30
+ run: (signal) => (0, __openstatus_health.expectOk)(doFetch(url, {
31
+ method: "GET",
32
+ headers,
33
+ signal
34
+ }))
35
+ };
36
+ }
37
+
38
+ //#endregion
39
+ exports.anthropicDefaultBaseUrl = anthropicDefaultBaseUrl;
40
+ exports.anthropicDefaultName = anthropicDefaultName;
41
+ exports.anthropicDefaultVersion = anthropicDefaultVersion;
42
+ exports.anthropicProbe = anthropicProbe;
package/dist/mod.d.cts ADDED
@@ -0,0 +1,25 @@
1
+ import { Probe, ProbeOverrides } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** API base URL when `baseUrl` is unset. */
6
+ declare const anthropicDefaultBaseUrl = "https://api.anthropic.com";
7
+ /** Probe name when `name` is unset. */
8
+ declare const anthropicDefaultName = "anthropic";
9
+ /** The `anthropic-version` header sent with the request. */
10
+ declare const anthropicDefaultVersion = "2023-06-01";
11
+ /** Options for `anthropicProbe()`. */
12
+ interface AnthropicProbeOptions extends ProbeOverrides {
13
+ /** An Anthropic API key (`sk-ant-…`). */
14
+ readonly apiKey: string;
15
+ /** API host. Default `anthropicDefaultBaseUrl`. */
16
+ readonly baseUrl?: string | URL;
17
+ /** Replacement `fetch`, for tests. */
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** A probe that expects 2xx from `GET {baseUrl}/v1/models` with `apiKey` in the `x-api-key` header; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey` or an invalid `baseUrl`. */
21
+ declare function anthropicProbe(options: AnthropicProbeOptions): Probe;
22
+ //# sourceMappingURL=mod.d.ts.map
23
+ //#endregion
24
+ export { AnthropicProbeOptions, anthropicDefaultBaseUrl, anthropicDefaultName, anthropicDefaultVersion, anthropicProbe };
25
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;AAsCA;AAA8B,cAjBjB,uBAAA,GAiBiB,2BAAA;;AAAkC,cAfnD,oBAAA,GAemD,WAAA;AAAK;cAbxD,uBAAA;;UAGI,qBAAA,SAA8B;;;;8BAIjB;;0BAEJ;;;iBAIV,cAAA,UAAwB,wBAAwB"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { Probe, ProbeOverrides } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** API base URL when `baseUrl` is unset. */
6
+ declare const anthropicDefaultBaseUrl = "https://api.anthropic.com";
7
+ /** Probe name when `name` is unset. */
8
+ declare const anthropicDefaultName = "anthropic";
9
+ /** The `anthropic-version` header sent with the request. */
10
+ declare const anthropicDefaultVersion = "2023-06-01";
11
+ /** Options for `anthropicProbe()`. */
12
+ interface AnthropicProbeOptions extends ProbeOverrides {
13
+ /** An Anthropic API key (`sk-ant-…`). */
14
+ readonly apiKey: string;
15
+ /** API host. Default `anthropicDefaultBaseUrl`. */
16
+ readonly baseUrl?: string | URL;
17
+ /** Replacement `fetch`, for tests. */
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** A probe that expects 2xx from `GET {baseUrl}/v1/models` with `apiKey` in the `x-api-key` header; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey` or an invalid `baseUrl`. */
21
+ declare function anthropicProbe(options: AnthropicProbeOptions): Probe;
22
+ //# sourceMappingURL=mod.d.ts.map
23
+ //#endregion
24
+ export { AnthropicProbeOptions, anthropicDefaultBaseUrl, anthropicDefaultName, anthropicDefaultVersion, anthropicProbe };
25
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;AAsCA;AAA8B,cAjBjB,uBAAA,GAiBiB,2BAAA;;AAAkC,cAfnD,oBAAA,GAemD,WAAA;AAAK;cAbxD,uBAAA;;UAGI,qBAAA,SAA8B;;;;8BAIjB;;0BAEJ;;;iBAIV,cAAA,UAAwB,wBAAwB"}
package/dist/mod.js ADDED
@@ -0,0 +1,39 @@
1
+ import { ProbeConfigError, expectOk, probeUrl } from "@openstatus/health";
2
+
3
+ //#region src/mod.ts
4
+ /** API base URL when `baseUrl` is unset. */
5
+ const anthropicDefaultBaseUrl = "https://api.anthropic.com";
6
+ /** Probe name when `name` is unset. */
7
+ const anthropicDefaultName = "anthropic";
8
+ /** The `anthropic-version` header sent with the request. */
9
+ const anthropicDefaultVersion = "2023-06-01";
10
+ /** A probe that expects 2xx from `GET {baseUrl}/v1/models` with `apiKey` in the `x-api-key` header; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey` or an invalid `baseUrl`. */
11
+ function anthropicProbe(options) {
12
+ const doFetch = options.fetch ?? globalThis.fetch;
13
+ const url = probeUrl({
14
+ probe: "anthropicProbe",
15
+ field: "baseUrl",
16
+ value: options.baseUrl ?? anthropicDefaultBaseUrl,
17
+ path: "/v1/models"
18
+ });
19
+ if (typeof options.apiKey !== "string" || options.apiKey.length === 0) throw new ProbeConfigError("anthropicProbe", "apiKey", typeof options.apiKey !== "string" ? `must be a string, got ${String(options.apiKey)}` : "must not be empty");
20
+ const headers = {
21
+ "x-api-key": options.apiKey,
22
+ "anthropic-version": anthropicDefaultVersion
23
+ };
24
+ return {
25
+ name: options.name ?? anthropicDefaultName,
26
+ critical: options.critical ?? false,
27
+ timeoutMs: options.timeoutMs,
28
+ skip: options.skip,
29
+ run: (signal) => expectOk(doFetch(url, {
30
+ method: "GET",
31
+ headers,
32
+ signal
33
+ }))
34
+ };
35
+ }
36
+
37
+ //#endregion
38
+ export { anthropicDefaultBaseUrl, anthropicDefaultName, anthropicDefaultVersion, anthropicProbe };
39
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","names":["options: AnthropicProbeOptions"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * Anthropic reachability probe for `@openstatus/health`, against `/v1/models`.\n *\n * ```ts\n * import { anthropicProbe } from \"@openstatus/health-anthropic\";\n *\n * const probe = anthropicProbe({ apiKey: env.ANTHROPIC_API_KEY });\n * ```\n *\n * @module\n */\n\nimport {\n expectOk,\n type Probe,\n ProbeConfigError,\n type ProbeOverrides,\n probeUrl,\n} from \"@openstatus/health\";\n\n/** API base URL when `baseUrl` is unset. */\nexport const anthropicDefaultBaseUrl = \"https://api.anthropic.com\";\n/** Probe name when `name` is unset. */\nexport const anthropicDefaultName = \"anthropic\";\n/** The `anthropic-version` header sent with the request. */\nexport const anthropicDefaultVersion = \"2023-06-01\";\n\n/** Options for `anthropicProbe()`. */\nexport interface AnthropicProbeOptions extends ProbeOverrides {\n /** An Anthropic API key (`sk-ant-…`). */\n readonly apiKey: string;\n /** API host. Default `anthropicDefaultBaseUrl`. */\n readonly baseUrl?: string | URL;\n /** Replacement `fetch`, for tests. */\n readonly fetch?: typeof fetch;\n}\n\n/** A probe that expects 2xx from `GET {baseUrl}/v1/models` with `apiKey` in the `x-api-key` header; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey` or an invalid `baseUrl`. */\nexport function anthropicProbe(options: AnthropicProbeOptions): Probe {\n const doFetch = options.fetch ?? globalThis.fetch;\n const url = probeUrl({\n probe: \"anthropicProbe\",\n field: \"baseUrl\",\n value: options.baseUrl ?? anthropicDefaultBaseUrl,\n path: \"/v1/models\",\n });\n if (typeof options.apiKey !== \"string\" || options.apiKey.length === 0) {\n throw new ProbeConfigError(\n \"anthropicProbe\",\n \"apiKey\",\n typeof options.apiKey !== \"string\"\n ? `must be a string, got ${String(options.apiKey)}`\n : \"must not be empty\",\n );\n }\n const headers = {\n \"x-api-key\": options.apiKey,\n \"anthropic-version\": anthropicDefaultVersion,\n };\n return {\n name: options.name ?? anthropicDefaultName,\n critical: options.critical ?? false,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: (signal) => expectOk(doFetch(url, { method: \"GET\", headers, signal })),\n };\n}\n"],"mappings":";;;;AAqBA,MAAa,0BAA0B;;AAEvC,MAAa,uBAAuB;;AAEpC,MAAa,0BAA0B;;AAavC,SAAgB,eAAeA,SAAuC;CACpE,MAAM,UAAU,QAAQ,SAAS,WAAW;CAC5C,MAAM,MAAM,SAAS;EACnB,OAAO;EACP,OAAO;EACP,OAAO,QAAQ,WAAW;EAC1B,MAAM;CACP,EAAC;AACF,YAAW,QAAQ,WAAW,YAAY,QAAQ,OAAO,WAAW,EAClE,OAAM,IAAI,iBACR,kBACA,iBACO,QAAQ,WAAW,YACrB,wBAAwB,OAAO,QAAQ,OAAO,CAAC,IAChD;CAGR,MAAM,UAAU;EACd,aAAa,QAAQ;EACrB,qBAAqB;CACtB;AACD,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,CAAC,WAAW,SAAS,QAAQ,KAAK;GAAE,QAAQ;GAAO;GAAS;EAAQ,EAAC,CAAC;CAC5E;AACF"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@openstatus/health-anthropic",
3
+ "version": "0.1.4-dev.0",
4
+ "description": "Anthropic API probe for @openstatus/health",
5
+ "keywords": [
6
+ "openstatus",
7
+ "health",
8
+ "healthcheck",
9
+ "anthropic",
10
+ "claude",
11
+ "llm",
12
+ "ai"
13
+ ],
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "openstatus",
17
+ "url": "https://www.openstatus.dev/"
18
+ },
19
+ "homepage": "https://github.com/openstatusHQ/health",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/openstatusHQ/health.git",
23
+ "directory": "packages/anthropic/"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/openstatusHQ/health/issues"
27
+ },
28
+ "type": "module",
29
+ "module": "./dist/mod.js",
30
+ "main": "./dist/mod.cjs",
31
+ "types": "./dist/mod.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": {
35
+ "import": "./dist/mod.d.ts",
36
+ "require": "./dist/mod.d.cts"
37
+ },
38
+ "import": "./dist/mod.js",
39
+ "require": "./dist/mod.cjs"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "sideEffects": false,
44
+ "files": [
45
+ "dist/"
46
+ ],
47
+ "engines": {
48
+ "node": ">=22"
49
+ },
50
+ "peerDependencies": {
51
+ "@openstatus/health": "^0.1.4-dev.0"
52
+ },
53
+ "devDependencies": {
54
+ "tsdown": "^0.12.7",
55
+ "typescript": "^5.8.3"
56
+ },
57
+ "scripts": {
58
+ "build": "tsdown",
59
+ "prepack": "tsdown",
60
+ "test": "node --experimental-transform-types --test"
61
+ }
62
+ }