The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
sdk-js: send the Asymptote API key only to Asymptote
Clauded1151c779639
diff --git a/docs/changelog/sdk.mdx b/docs/changelog/sdk.mdxindex ab527b84..44d01e60 100644--- a/docs/changelog/sdk.mdx+++ b/docs/changelog/sdk.mdx@@ -9,6 +9,13 @@ Stay up to date with the latest changes to the Beacon Observe SDK.---+## Unreleased++- **API key scoped to Beacon Cloud** · `ASYMPTOTE_API_KEY` is now sent only to Beacon Cloud: in hosted mode, or to an explicit OTLP endpoint on the same origin as the base URL. Previously a service with both `ASYMPTOTE_API_KEY` and a generic `OTEL_EXPORTER_OTLP_ENDPOINT` sent the key to that collector on every export. Caller-supplied `headers` are unchanged.+- **HTTPS required for the API key** · `Observe.initialize()` now throws when the key would be sent to a non-loopback `http://` base URL. `http://localhost`, `http://127.0.0.1` and `http://[::1]` remain allowed for local stubs.++---+## June 2026### v0.1.0 · June 10, 2026diff --git a/docs/sdk/quickstart.mdx b/docs/sdk/quickstart.mdxindex e75bbadb..4fe03ff9 100644--- a/docs/sdk/quickstart.mdx+++ b/docs/sdk/quickstart.mdx@@ -47,6 +47,8 @@ Hosted export uses OTLP/HTTP traces.The SDK appends `/v1/observe` when the configured base URL or endpoint does not already include it.+The base URL must use `https://`. Plain `http://` is accepted only for loopback (`localhost`, `127.0.0.1`, `[::1]`), so a local stub keeps working; any other `http://` base URL with an API key makes `Observe.initialize()` throw instead of sending the key in cleartext.+### Customer-managed OTLPUse an explicit OTLP endpoint when traces should go to a local or customer-managed collector instead of Beacon Cloud hosted Observe:@@ -63,7 +65,7 @@ Observe.initialize({});```-Explicit OTLP export does not require a Beacon Cloud API key.+Explicit OTLP export does not require a Beacon Cloud API key, and does not send one. When `ASYMPTOTE_API_KEY` is also set, the SDK attaches it only if the OTLP endpoint has the same origin (scheme, host and port) as the Beacon Cloud base URL; a third-party or customer collector never receives it. Headers you pass in `initialize({ headers })`, including your own `authorization`, are sent unchanged.## 3. Create a first tracediff --git a/docs/sdk/reference.mdx b/docs/sdk/reference.mdxindex 53c5f666..588bd77a 100644--- a/docs/sdk/reference.mdx+++ b/docs/sdk/reference.mdx@@ -64,6 +64,8 @@ Function exports are also available for the same operations, including `initiali| `otlp` | `otlpEndpoint` or `OTEL_EXPORTER_OTLP_ENDPOINT` is present || `custom` | Default exporter is disabled or a custom span exporter is provided |+The API key is sent as `authorization: Bearer <api key>` only to Beacon Cloud: in `hosted` mode, or in `otlp` mode when the endpoint has the same origin as `baseUrl`. It is never attached in `custom` mode or to an OTLP endpoint on another origin, and a caller-supplied `authorization` header in `headers` always wins. A URL that carries the key must be `https://`, except loopback (`localhost`, `127.0.0.1`, `[::1]`) over `http://`; otherwise `initialize()` throws.+## Beacon compatibility attributesCloud SDKs should prefer standard OpenTelemetry attributes when they exist, especially `gen_ai.*` attributes for model and prompt metadata. Use Beacon attributes for fields that need to normalize into Beacon endpoint-style events.diff --git a/packages/asymptote-sdk-js/README.md b/packages/asymptote-sdk-js/README.mdindex 85e288c3..91c2eb1c 100644--- a/packages/asymptote-sdk-js/README.md+++ b/packages/asymptote-sdk-js/README.md@@ -26,6 +26,10 @@ Hosted Observe contract:- Observe path: `/v1/observe` is appended when the endpoint does not already include it.- Auth: `authorization: Bearer <ASYMPTOTE_API_KEY>`.- Override base URL with `ASYMPTOTE_BASE_URL` or `initialize({ baseUrl })`.+- The base URL must be `https://`. Plain `http://` is accepted only for+ loopback (`localhost`, `127.0.0.1`, `[::1]`); any other `http://` base URL+ with an API key makes `initialize()` throw rather than send the key in+ cleartext.The TypeScript SDK preserves this hosted contract, but this repository does notimplement the managed ingest service. Use `baseUrl` with a local stub in tests.@@ -50,6 +54,14 @@ Endpoint precedence:2. `OTEL_EXPORTER_OTLP_ENDPOINT`3. hosted `baseUrl` when an API key is present+The API key is sent only to Asymptote. When an explicit OTLP endpoint wins,+the SDK attaches `authorization: Bearer <ASYMPTOTE_API_KEY>` only if that+endpoint has the same origin (scheme, host and port) as the Asymptote base URL.+A service that has both `ASYMPTOTE_API_KEY` and a generic+`OTEL_EXPORTER_OTLP_ENDPOINT` for another collector exports to that collector+without the key. Headers you pass in `initialize({ headers })`, including your+own `authorization`, are sent unchanged.+Beacon endpoint installs remain local-first and never require hosted credentials.## Automatic AI Instrumentationdiff --git a/packages/asymptote-sdk-js/src/index.test.ts b/packages/asymptote-sdk-js/src/index.test.tsindex 61428b97..4387a7d4 100644--- a/packages/asymptote-sdk-js/src/index.test.ts+++ b/packages/asymptote-sdk-js/src/index.test.ts@@ -94,6 +94,100 @@ describe("resolveExporterConfig", () => {expect(config.observeUrl).toBe("http://127.0.0.1:9999/v1/observe");});+ it("does not send the api key to a foreign OTLP endpoint from env", () => {+ process.env.ASYMPTOTE_API_KEY = "secret-key";+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://collector.example:4318";++ const config = resolveExporterConfig();++ expect(config.mode).toBe("otlp");+ expect(config.observeUrl).toBe("http://collector.example:4318/v1/observe");+ expect(config.headers.authorization).toBeUndefined();+ expect(JSON.stringify(config.headers)).not.toContain("secret-key");+ });++ it("does not send the api key to a foreign OTLP endpoint option", () => {+ const config = resolveExporterConfig({ apiKey: "secret-key", otlpEndpoint: "https://otel.vendor.example" });++ expect(config.mode).toBe("otlp");+ expect(config.headers.authorization).toBeUndefined();+ });++ it("does not treat a different port or scheme as the Asymptote origin", () => {+ expect(+ resolveExporterConfig({ apiKey: "k", otlpEndpoint: "https://api.asymptotelabs.ai:8443" }).headers.authorization,+ ).toBeUndefined();+ expect(+ resolveExporterConfig({ apiKey: "k", otlpEndpoint: "http://api.asymptotelabs.ai" }).headers.authorization,+ ).toBeUndefined();+ });++ it("sends the api key to an OTLP endpoint on the Asymptote origin", () => {+ const config = resolveExporterConfig({ apiKey: "test-key", otlpEndpoint: "https://api.asymptotelabs.ai:443/v1/observe" });++ expect(config.mode).toBe("otlp");+ expect(config.headers.authorization).toBe("Bearer test-key");+ });++ it("sends the api key to an OTLP endpoint on a configured base URL origin", () => {+ process.env.ASYMPTOTE_BASE_URL = "https://observe.example";+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://observe.example/";++ const config = resolveExporterConfig({ apiKey: "test-key" });++ expect(config.mode).toBe("otlp");+ expect(config.headers.authorization).toBe("Bearer test-key");+ });++ it("refuses to send the api key over http to a non-loopback base URL", () => {+ expect(() => resolveExporterConfig({ apiKey: "test-key", baseUrl: "http://observe.example" })).toThrow(+ /refuses to send ASYMPTOTE_API_KEY over http/,+ );+ });++ it("refuses an insecure base URL from env when the key would be sent", () => {+ process.env.ASYMPTOTE_API_KEY = "env-key";+ process.env.ASYMPTOTE_BASE_URL = "http://observe.example";++ expect(() => resolveExporterConfig()).toThrow(/https/);+ });++ it("ignores an insecure base URL when the key goes nowhere", () => {+ process.env.ASYMPTOTE_BASE_URL = "http://observe.example";++ const config = resolveExporterConfig({ apiKey: "k", otlpEndpoint: "http://127.0.0.1:4318" });++ expect(config.headers.authorization).toBeUndefined();+ });++ it("allows the api key over http to loopback base URLs", () => {+ for (const baseUrl of ["http://127.0.0.1:4318", "http://localhost:4318", "http://[::1]:4318"]) {+ const config = resolveExporterConfig({ apiKey: "test-key", baseUrl });++ expect(config.mode).toBe("hosted");+ expect(config.headers.authorization).toBe("Bearer test-key");+ }+ });++ it("preserves a caller-supplied authorization header", () => {+ const hosted = resolveExporterConfig({ apiKey: "test-key", headers: { Authorization: "Basic custom" } });+ expect(hosted.headers).toEqual({ Authorization: "Basic custom" });++ const foreign = resolveExporterConfig({+ apiKey: "test-key",+ otlpEndpoint: "http://collector.example:4318",+ headers: { authorization: "Bearer collector-token" },+ });+ expect(foreign.headers).toEqual({ authorization: "Bearer collector-token" });+ });++ it("does not attach the api key in custom mode", () => {+ const config = resolveExporterConfig({ apiKey: "test-key", disableDefaultExporter: true });++ expect(config.mode).toBe("custom");+ expect(config.headers.authorization).toBeUndefined();+ });+it("throws when neither hosted credentials nor explicit OTLP are configured", () => {expect(() => resolveExporterConfig()).toThrow(/ASYMPTOTE_API_KEY/);});diff --git a/packages/asymptote-sdk-js/src/index.ts b/packages/asymptote-sdk-js/src/index.tsindex f6fa061e..bb37bc78 100644--- a/packages/asymptote-sdk-js/src/index.ts+++ b/packages/asymptote-sdk-js/src/index.ts@@ -381,12 +381,62 @@ export function resolveExporterConfig(options: InitializeOptions = {}): Resolvedconst observeUrl = skipDefault ? undefined : explicitEndpoint ? observeURL(explicitEndpoint) : observeURL(baseUrl);const headers: Record<string, string> = { ...(options.headers ?? {}) };- if (apiKey && !headers.authorization && !headers.Authorization) {+ const callerSetAuthorization = Object.keys(headers).some(name => name.toLowerCase() === "authorization");+ if (apiKey && observeUrl && !callerSetAuthorization && exportsToAsymptote(mode, observeUrl, baseUrl)) {+ requireSecureKeyURL(observeUrl);headers.authorization = `Bearer ${apiKey}`;}return { observeUrl, headers, mode };}+// The Asymptote API key is a credential for Asymptote's own ingest, so it is+// sent only there: in hosted mode, or when an explicit OTLP endpoint has the+// same origin as the configured Asymptote base URL. OTEL_EXPORTER_OTLP_ENDPOINT+// is an ambient, vendor-neutral variable that usually names a third-party or+// customer collector, which must never receive the key.+function exportsToAsymptote(mode: ExportMode, observeUrl: string, baseUrl: string): boolean {+ if (mode === "hosted") {+ return true;+ }+ if (mode !== "otlp") {+ return false;+ }+ const endpointOrigin = urlOrigin(observeUrl);+ return endpointOrigin !== undefined && endpointOrigin === urlOrigin(baseUrl);+}++function urlOrigin(value: string): string | undefined {+ try {+ const origin = new URL(value).origin;+ return origin === "null" ? undefined : origin;+ } catch {+ return undefined;+ }+}++const LOOPBACK_HOSTNAMES = new Set(["localhost", "127.0.0.1", "[::1]"]);++// A URL that carries the API key must be https, except loopback over http so+// local stubs and collectors keep working.+function requireSecureKeyURL(value: string): void {+ let url: URL;+ try {+ url = new URL(value);+ } catch {+ throw new Error(`Asymptote SDK refuses to send ASYMPTOTE_API_KEY to an invalid URL: ${JSON.stringify(value)}`);+ }+ if (url.protocol === "https:") {+ return;+ }+ if (url.protocol === "http:" && LOOPBACK_HOSTNAMES.has(url.hostname.toLowerCase())) {+ return;+ }+ throw new Error(+ `Asymptote SDK refuses to send ASYMPTOTE_API_KEY over ${url.protocol.replace(/:$/, "")} to ${url.host}; ` ++ "use an https:// base URL (plain http is allowed only for localhost, 127.0.0.1, and [::1])",+ );+}+function makeSpanProcessor(exporter: SpanExporter, options: InitializeOptions): SpanProcessor {return options.disableBatch? new SimpleSpanProcessor(exporter)