{"_id":"merge-gateway-sdk","_rev":"4-830aa8d156c7d153774df02491daf117","name":"merge-gateway-sdk","dist-tags":{"latest":"0.4.0"},"versions":{"0.2.0":{"name":"merge-gateway-sdk","version":"0.2.0","keywords":["merge","gateway","ai","llm","sdk","openai","anthropic"],"author":{"name":"Merge","email":"support@merge.dev"},"license":"MIT","_id":"merge-gateway-sdk@0.2.0","maintainers":[{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"}],"homepage":"https://github.com/merge-api/merge-gateway-typescript-sdk","bugs":{"url":"https://github.com/merge-api/merge-gateway-typescript-sdk/issues"},"dist":{"shasum":"97cdc2063f109a948e46b99207780d3be6f0c053","tarball":"https://registry.npmjs.org/merge-gateway-sdk/-/merge-gateway-sdk-0.2.0.tgz","fileCount":63,"integrity":"sha512-SaT2HU3EMm+yW4fq7QDdgwsDt2sApV2hha/1njXQkJ0foFKpbXVATqzkoaOPCAiQ0qTJPPdwRwNIRq5J9SxlvQ==","signatures":[{"sig":"MEYCIQDq3lTix4n42XWFIuPTw3HgaMunnPu+tm740X1X5iYjGwIhAMoCikKHHIBe4IPk0PWgY77dDH1F7Iey8bsdL7cmFCB3","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56331},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18"},"gitHead":"f21876a67274a9b10eedd8034a21d817df8461a9","scripts":{"test":"vitest run","build":"tsc","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"},"repository":{"url":"git+https://github.com/merge-api/merge-gateway-typescript-sdk.git","type":"git"},"_npmVersion":"10.8.2","description":"TypeScript SDK for the Merge Gateway API","directories":{},"_nodeVersion":"18.20.8","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.0.0","typescript":"~5.7.0"},"_npmOperationalInternal":{"tmp":"tmp/merge-gateway-sdk_0.2.0_1774834732023_0.5476667188850799","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"merge-gateway-sdk","version":"0.3.0","keywords":["merge","gateway","ai","llm","sdk","openai","anthropic"],"author":{"name":"Merge","email":"support@merge.dev"},"license":"MIT","_id":"merge-gateway-sdk@0.3.0","maintainers":[{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"}],"homepage":"https://github.com/merge-api/merge-gateway-typescript-sdk","bugs":{"url":"https://github.com/merge-api/merge-gateway-typescript-sdk/issues"},"dist":{"shasum":"615de67724cc49e6bd30b1e1219fec882180632c","tarball":"https://registry.npmjs.org/merge-gateway-sdk/-/merge-gateway-sdk-0.3.0.tgz","fileCount":71,"integrity":"sha512-UkmQqjdPndx4VmKvEvSMJb7XPoiMxyNjUyZeSS5xd1eC7g6ygKlfr4w8U4B0NldVa24vfzHlNGVMWBAHiTnxoA==","signatures":[{"sig":"MEYCIQCy7CZ23jkQZdDh0OwQ98s+NhbAYlCIeF7Z1eaFBvohmAIhAIk4Wrikvg+gNg1zDRbCRpR7zgB+B0bc1wo/vrQQX9UE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":90771},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18"},"gitHead":"c2d8a3e14dcfa140dbc6acd19984480b7cc88e40","scripts":{"test":"vitest run","build":"tsc","check:sdk":"node scripts/local-check.mjs --sdk-only","test:watch":"vitest","check:local":"node scripts/local-check.mjs","prepublishOnly":"npm run build","check:published":"node scripts/local-check.mjs --published-only"},"_npmUser":{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"},"repository":{"url":"git+https://github.com/merge-api/merge-gateway-typescript-sdk.git","type":"git"},"_npmVersion":"10.9.4","description":"TypeScript SDK for the Merge Gateway API","directories":{},"_nodeVersion":"22.22.1","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.0.0","typescript":"~5.7.0"},"_npmOperationalInternal":{"tmp":"tmp/merge-gateway-sdk_0.3.0_1784144236837_0.9971092232671142","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"name":"merge-gateway-sdk","version":"0.3.1","keywords":["merge","gateway","ai","llm","sdk","openai","anthropic"],"author":{"name":"Merge","email":"support@merge.dev"},"license":"MIT","_id":"merge-gateway-sdk@0.3.1","maintainers":[{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"}],"homepage":"https://github.com/merge-api/merge-gateway-typescript-sdk","bugs":{"url":"https://github.com/merge-api/merge-gateway-typescript-sdk/issues"},"dist":{"shasum":"8633fea49c9504960f3a5a09576ed0c5058865ca","tarball":"https://registry.npmjs.org/merge-gateway-sdk/-/merge-gateway-sdk-0.3.1.tgz","fileCount":71,"integrity":"sha512-OD57PerwIom7guL9W0dvEeHoB4eXNPEPoWWyv+6WU3fhNurgefTYU6dO2OiMO8hPGrCWn8gTyv40AFfhwXtKbg==","signatures":[{"sig":"MEYCIQCNonNSGh3ud3o8Y9r07/jGUwuq127Z9ePO49peR5A6hQIhAK+0IQILwaTZ13yUylY4vV6zugPc55U9PwlPBBBumGxA","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":91099},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18"},"gitHead":"5efdcc328db409cc318b71988e628e9dbd802c29","scripts":{"test":"vitest run","build":"tsc","check:sdk":"node scripts/local-check.mjs --sdk-only","test:watch":"vitest","check:local":"node scripts/local-check.mjs","prepublishOnly":"npm run build","check:published":"node scripts/local-check.mjs --published-only"},"_npmUser":{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"},"repository":{"url":"git+https://github.com/merge-api/merge-gateway-typescript-sdk.git","type":"git"},"_npmVersion":"10.9.4","description":"TypeScript SDK for the Merge Gateway API","directories":{},"_nodeVersion":"22.22.1","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.0.0","typescript":"~5.7.0"},"_npmOperationalInternal":{"tmp":"tmp/merge-gateway-sdk_0.3.1_1785789192153_0.4841790613460617","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"merge-gateway-sdk","version":"0.4.0","description":"TypeScript SDK for the Merge Gateway API","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","check:local":"node scripts/local-check.mjs","check:published":"node scripts/local-check.mjs --published-only","check:sdk":"node scripts/local-check.mjs --sdk-only","test":"vitest run","test:watch":"vitest","prepublishOnly":"npm run build"},"engines":{"node":">=18"},"keywords":["merge","gateway","ai","llm","sdk","openai","anthropic"],"author":{"name":"Merge","email":"support@merge.dev"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/merge-api/merge-gateway-typescript-sdk.git"},"homepage":"https://github.com/merge-api/merge-gateway-typescript-sdk","devDependencies":{"typescript":"~5.7.0","vitest":"^3.0.0","zod":"^4.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./zod":{"types":"./dist/zod.d.ts","default":"./dist/zod.js"},"./package.json":"./package.json"},"peerDependencies":{"zod":"^4.0.0"},"peerDependenciesMeta":{"zod":{"optional":true}},"_id":"merge-gateway-sdk@0.4.0","gitHead":"2758cce4ba00b6ac473e6347d41dc421cc5a7208","bugs":{"url":"https://github.com/merge-api/merge-gateway-typescript-sdk/issues"},"_nodeVersion":"22.22.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-ODqQqOa/JJow1BWJjJxHWFcqKh/7cr61SwJ8qNxPCzsxuMfxv6+VkjnO+GmDFtmm5X4ehV2oR8UkRKuQJun9hQ==","shasum":"4c31ed52598938f7da48b43c208bcb56f6d82411","tarball":"https://registry.npmjs.org/merge-gateway-sdk/-/merge-gateway-sdk-0.4.0.tgz","fileCount":75,"unpackedSize":109856,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIF3z3RPkvpV9nqXvp7MKBQ3hcDqfsw5MvoFrOC6E4PGiAiBTLs0l/mrtHr9lrGDsYl520VjygA6gHdxkWi8zFhKjJw=="}]},"_npmUser":{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"},"directories":{},"maintainers":[{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/merge-gateway-sdk_0.4.0_1786552355926_0.8201374989606778"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-30T01:38:52.022Z","modified":"2026-08-12T16:32:36.333Z","0.2.0":"2026-03-30T01:38:52.182Z","0.3.0":"2026-07-15T19:37:16.966Z","0.3.1":"2026-08-03T20:33:12.301Z","0.4.0":"2026-08-12T16:32:36.068Z"},"bugs":{"url":"https://github.com/merge-api/merge-gateway-typescript-sdk/issues"},"author":{"name":"Merge","email":"support@merge.dev"},"license":"MIT","homepage":"https://github.com/merge-api/merge-gateway-typescript-sdk","keywords":["merge","gateway","ai","llm","sdk","openai","anthropic"],"repository":{"type":"git","url":"git+https://github.com/merge-api/merge-gateway-typescript-sdk.git"},"description":"TypeScript SDK for the Merge Gateway API","maintainers":[{"name":"aakash.gupte","email":"aakash.gupte@merge.dev"}],"readme":"# merge-gateway-sdk\n\nTypeScript SDK for the [Merge Gateway](https://merge.dev) API.\n\n## Installation\n\n```bash\nnpm install merge-gateway-sdk\n```\n\n## Quick start\n\n```typescript\nimport { MergeGateway } from \"merge-gateway-sdk\";\n\nconst client = new MergeGateway({ apiKey: \"mg_...\" });\n```\n\n## Usage\n\n### Responses\n\n```typescript\n// Non-streaming\nconst response = await client.responses.create({\n  model: \"openai/gpt-4o\",\n  input: [{ type: \"message\", role: \"user\", content: \"Tell me a bedtime story about an otter.\" }],\n});\nconsole.log(response.output[0].content[0]);\n\n// Streaming\nconst stream = await client.responses.create({\n  model: \"openai/gpt-4o\",\n  input: [{ type: \"message\", role: \"user\", content: \"Hello\" }],\n  stream: true,\n});\nfor await (const event of stream) {\n  console.log(event);\n}\n```\n\n### Models\n\n```typescript\n// List models (with optional pagination)\nconst models = await client.models.list();\nfor (const m of models.data) {\n  console.log(m.id, m.display_name);\n}\n\n// Filter by provider\nconst openaiModels = await client.models.list({ provider: \"openai\" });\n\n// Retrieve a specific model\nconst model = await client.models.retrieve(\"openai/gpt-4o\");\n```\n\n### Embeddings\n\n```typescript\nconst result = await client.embeddings.create({\n  model: \"openai/text-embedding-3-small\",\n  input: \"The food was delicious\",\n  encoding_format: \"float\",\n});\nconsole.log(result.data[0].embedding);\n```\n\n### Tags\n\n```typescript\nconst tags = await client.tags.list();\nfor (const tag of tags.data) {\n  console.log(tag.tag_key, tag.tag_value);\n}\n```\n\n### Embedded Routing (customers)\n\nProvision each of your end customers as a Customer with its own routing policies, provider keys, and budget, then scope LLM requests to it with the `customer` field.\n\n```typescript\n// Provision a customer\nconst customer = await client.customers.create({ name: \"Acme\", origin_id: \"acme-corp\" });\n\nawait client.customers.routingPolicies.create(customer.id, {\n  name: \"workflow-a\",\n  strategy: \"PRIORITY\",\n  is_default: true,\n  priority_order: [\n    { model: \"openai/gpt-5.5\", priority: 1 },\n    { model: \"anthropic/claude-opus-4-8\", priority: 2 },\n  ],\n});\n\nawait client.customers.keys.upsert(customer.id, { vendor: \"openai\", api_key: \"sk-...\" });\n\nawait client.customers.budgets.create(customer.id, {\n  spending_limit: 50,\n  reset_period: \"MONTHLY\",\n  spending_limit_type: \"HARD\",\n});\n\n// Scope a request to the customer (omit `model` to route via its default policy)\nconst response = await client.responses.create({ input: \"Hello!\", customer: customer.id });\n\n// Per-customer spend report\nconst usage = await client.customers.usage(customer.id, {\n  start: \"2026-07-01\",\n  end: \"2026-07-31\",\n});\nconsole.log(usage.customer_byok_spend, usage.organization_byok_spend, usage.merge_spend);\n```\n\n### Structured output\n\nRequest schema-constrained JSON with `response_format`. `strict` is\ntri-state: omit it for the provider default, set `false` for schemas with\noptional fields or unions (OpenAI-style strict mode rejects those). If the\nrouted model can't honor the schema, the gateway returns a clear\n`400 unsupported_params` — never silent best-effort JSON.\n\n```typescript\nconst response = await client.responses.create({\n  model: \"openai/gpt-4o\",\n  input: \"Invent a person\",\n  response_format: {\n    type: \"json_schema\",\n    json_schema: {\n      name: \"person\",\n      schema: {\n        type: \"object\",\n        properties: { name: { type: \"string\" }, age: { type: \"integer\" } },\n        required: [\"name\", \"age\"],\n        additionalProperties: false,\n      },\n      strict: true,\n    },\n  },\n});\n```\n\nWith Zod (v4, optional peer dependency):\n\n```typescript\nimport { zodResponseFormat } from \"merge-gateway-sdk/zod\";\nimport { z } from \"zod\";\n\nconst Person = z.object({ name: z.string(), age: z.number().optional() });\n\nconst response = await client.responses.create({\n  model: \"openai/gpt-4o\",\n  input: \"Invent a person\",\n  response_format: zodResponseFormat(Person, \"person\", { strict: false }),\n});\n```\n\n### Error handling\n\n```typescript\nimport { MergeGateway, AuthenticationError, RateLimitError } from \"merge-gateway-sdk\";\n\ntry {\n  const response = await client.responses.create({ model: \"openai/gpt-4o\", input: \"Hi\" });\n} catch (e) {\n  if (e instanceof AuthenticationError) {\n    console.log(\"Check your API key\");\n  } else if (e instanceof RateLimitError) {\n    console.log(\"Slow down!\");\n  }\n}\n```\n\n## Publishing to npm\n\n```bash\nnpm run build\nnpm publish\n```\n\n## Testing locally\n\n```bash\nnpm ci\nnpm run check:local\n```\n\n`check:local` runs:\n\n- `npm run build`\n- `npm test`\n- `npm pack --dry-run` to verify the package contains the built `dist` entrypoint\n- a live SDK smoke test when `MERGE_GATEWAY_API_KEY` is set\n- a best-effort npm registry lookup for `merge-gateway-sdk`\n\nThe live SDK smoke test imports the built package from `dist` and calls:\n\n- `client.models.list()`\n- `client.models.retrieve(...)`\n- `client.tags.list()`\n- `client.responses.create(...)`\n- `client.responses.create({ stream: true, ... })`\n- `client.embeddings.create(...)`\n\nTo run those same live SDK calls against the currently published npm package:\n\n```bash\nMERGE_GATEWAY_API_KEY=\"mg_...\" npm run check:published\n```\n\nBy default, `check:published` installs `merge-gateway-sdk` at the version in\nthis repo's `package.json` into an isolated temp directory, imports that\ninstalled package, and runs the same smoke test calls. To test a different\npublished version:\n\n```bash\nMERGE_GATEWAY_PUBLISHED_VERSION=\"0.2.0\" MERGE_GATEWAY_API_KEY=\"mg_...\" npm run check:published\n```\n\nTo run the live SDK calls locally, set the API key only in your terminal session:\n\n```bash\nexport MERGE_GATEWAY_API_KEY=\"mg_...\"\nnpm run check:sdk\n```\n\nOr pass it for a single command:\n\n```bash\nMERGE_GATEWAY_API_KEY=\"mg_...\" npm run check:sdk\n```\n\nDo not put the API key in this repo or commit it in a `.env` file. The script\nreads `MERGE_GATEWAY_API_KEY` from the process environment at runtime.\n\nUseful variants:\n\n```bash\n# Run everything except the public npm registry lookup\nnpm run check:local -- --skip-npm\n\n# Only check whether the package name/version is published on npm\nnpm run check:local -- --npm-only\n\n# Fail if the current local version is not already published\nnpm run check:local -- --strict-npm\n\n# Run live SDK calls without the streaming response check\nnpm run check:sdk -- --skip-stream\n\n# Run the published package check without the streaming response check\nnpm run check:published -- --skip-stream\n\n# Print detailed failure context, including raw SDK responses\nnpm run check:sdk -- --verbose\n\n# Use a specific model if the script cannot pick one from models.list()\nMERGE_GATEWAY_TEST_MODEL=\"openai/gpt-4o\" MERGE_GATEWAY_API_KEY=\"mg_...\" npm run check:sdk\n```\n\nFlags:\n\n- `--sdk-only`: Build the package and only run live SDK method smoke tests.\n- `--skip-build`: Skip `npm run build`.\n- `--skip-tests`: Skip `npm test`.\n- `--skip-pack`: Skip `npm pack --dry-run`.\n- `--skip-npm`: Skip the public npm registry lookup.\n- `--skip-sdk`: Skip live SDK method smoke tests.\n- `--skip-stream`: Skip the streaming `responses.create` smoke test.\n- `--npm-only`: Only check whether the package exists on npm.\n- `--published-only`: Install the published package from npm and only run live SDK method smoke tests.\n- `--published-sdk`: Run live SDK method smoke tests against the published package instead of local `dist`.\n- `--strict-npm`: Fail if the current package version is not published on npm.\n- `--strict-sdk`: Fail instead of skipping when `MERGE_GATEWAY_API_KEY` is missing.\n- `--verbose`: Print detailed failure context, including raw SDK responses.\n- `--help`: Print all script options.\n\nOptional environment variables:\n\n- `MERGE_GATEWAY_BASE_URL`\n- `MERGE_GATEWAY_PUBLISHED_VERSION`\n- `MERGE_GATEWAY_TEST_MODEL`\n- `MERGE_GATEWAY_TEST_EMBEDDING_MODEL`\n- `MERGE_GATEWAY_TEST_TIMEOUT_MS`\n- `MERGE_GATEWAY_DEBUG=1`\n","readmeFilename":"README.md"}