--- title: TypeScript | Stainless description: Generate production-ready TypeScript SDKs from your OpenAPI specification --- TypeScript is fully supported. The Stainless TypeScript SDK generator creates idiomatic, type-safe TypeScript client libraries from your OpenAPI specification. The TypeScript target uses built-in `fetch` for HTTP requests, making SDKs dependency-free by default. **Example repositories:** - [openai/openai-node](https://github.com/openai/openai-node) - [anthropics/anthropic-sdk-typescript](https://github.com/anthropics/anthropic-sdk-typescript) - [lithic-com/lithic-node](https://github.com/lithic-com/lithic-node) - [Modern-Treasury/modern-treasury-node](https://github.com/Modern-Treasury/modern-treasury-node) - [turbopuffer/turbopuffer-typescript](https://github.com/turbopuffer/turbopuffer-typescript) You can generate an [MCP (Model Context Protocol) server](/docs/targets/mcp/index.md) as a subpackage of your TypeScript SDK to enable AI assistants to interact with your API. ## Configuration To generate a TypeScript SDK, add the `typescript` target to your Stainless configuration file: ``` targets: typescript: package_name: my-company-sdk edition: typescript.2025-10-10 ``` ### Common configuration options ``` targets: typescript: package_name: my-company-sdk # Specify the edition edition: typescript.2025-10-10 # Specify the package manager (default: pnpm) package_manager: pnpm # or: yarn, npm # Configure publishing publish: npm: true jsr: package_name: "@my-scope/my-sdk" ``` For a complete list of configuration options, see the [TypeScript target reference](/docs/reference/config#typescript/index.md). ## Editions Editions allow Stainless to make improvements to SDKs that aren’t backwards-compatible. You can explicitly opt in to new editions when you’re ready. See the [SDK and config editions reference](/docs/reference/editions/index.md) for more information. #### typescript.2025-10-10 - Changed default package manager from yarn to pnpm - To revert to yarn, set `options.package_manager: yarn` #### typescript.2025-10-08 - Initial edition for TypeScript (used by default if no edition is specified) ## Publishing to npm Package your TypeScript SDK for distribution on [npm](https://www.npmjs.com/), making it easy for users to install with `npm install`. Before publishing, you need to [link a production repository](/docs/guides/publish#link-production-repos/index.md) where Stainless will push your SDK code. We also recommend using trusted publishing via OIDC as granular access tokens expire after 90 days. - [Trusted Publishing (OIDC) \[Recommended\]](#tab-panel-23) - [Access Tokens](#tab-panel-24) NPM only allows for trusted publishing to be configured on an existing package. If you’re releasing your SDK for the first time to a new NPM package, you’ll need to publish manually first. After your first release, you can switch to OIDC. Publish your package to npm for the first time Before you can configure trusted publishing, npm requires that your package already exists. Follow these steps to publish your SDK manually for the first time: 1. Clone your SDK’s production repository and navigate to it. 2. Install dependencies and build the SDK: Terminal window ``` pnpm install pnpm build ``` 3. Navigate to the `dist` directory where the publishable package is located: Terminal window ``` cd dist ``` 4. Log in to npm: Terminal window ``` npm login ``` This opens a browser window to complete the npm OAuth flow. Follow the prompts to authenticate. 5. Publish the package: Terminal window ``` pnpm publish ``` If you’re publishing a scoped package (e.g., `@my-org/my-sdk`), you may need to use `pnpm publish --access public` to make it publicly available. After your package is published, you can proceed to configure trusted publishing. Setup GitHub Actions as a trusted publisher 1. Navigate to your packages settings at `npmjs.com/package//access` and under the **Trusted Publisher** section choose **GitHub Actions**. 2. Fill in the *organization or user* where your SDK’s repository lives and the repository’s *name*. 3. Put in `publish-npm.yml` as the **workflow filename**. 4. **\[Recommended]** If you utilize a specific [Github Actions environment](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments) for releases, you should specify it for **environment name**. This will make it so only release workflows running in that environment can publish. The release environment is set in your [Stainless config](/docs/reference/config/#codeflow-config/index.md) like so: ``` codeflow: release_environment: # ... ``` 5. Click **Set up connection**. Update your Stainless config Update the [Stainless config](/docs/reference/config#typescript/index.md) to specify OIDC authentication and save. ``` targets: typescript: package_name: publish: npm: auth_method: oidc ``` Use access tokens to authenticate with npm. Note that granular access tokens expire after 90 days and will need to be rotated. Get an access token 1. Log in or sign up at [npm](https://www.npmjs.com/). 2. Select your profile picture on the top right to open a dropdown. 3. Navigate to **Access Tokens** > **Generate New Token**. 4. Choose a token version: - *Classic Token*, with **Automation** as the token type. This token will be scoped to your whole account. - *Granular Access Token*, scoped to the NPM package you’re publishing. The token needs read and write permissions. If you don’t have an existing NPM package, you can make an empty one as a starting point. Add the token to your production repo 1. In the production repo, navigate to **Secrets and variables** > **Actions** > **New repository secret**. The URL should look like `https://github.com///settings/secrets/actions/new`. 2. Add a new secret named `NPM_TOKEN` with your API token. Choose a package name and update your Stainless config 1. Choose an available package name. You can make your package organization scoped (`@/`), but you will need to use a Granular Access Token that has Read and Write permissions for the right NPM organization. Trying to publish an organization scoped package using a Classic Token will result in an error. You can [check](https://remarkablemark.org/npm-package-name-checker/) if the name is available. If you are using an existing NPM package, check the publishing access, under package settings, so that it doesn’t require two-factor authentication. 1. Update the [Stainless config](/docs/reference/config#typescript/index.md) with your package name and save. ``` targets: typescript: package_name: publish: npm: true ``` ## Publishing to JSR (Deno) Publish your TypeScript SDK to [JSR](https://jsr.io/) for use with Deno and other JavaScript runtimes. - [GitHub OIDC \[Recommended\]](#tab-panel-21) - [Access Token](#tab-panel-22) Create a JSR package 1. Log in or sign up at [JSR](https://jsr.io/). 2. Select **Publish a package**. 3. Choose an appropriate scope and package name. 4. Select **Create**. Link your production repo and configure security 1. In JSR, navigate to **\** > **Settings** > **GitHub Repository**. 2. Link the production repo to the JSR package you created. 3. Navigate to your **\** > **Settings** > **GitHub Actions security**. 4. Select **Do not restrict publishing**. This will let the Stainless GitHub App publish even though it is not a member of your scope. Update your Stainless config Update the [Stainless config](/docs/reference/config#typescript/index.md) with your package name and save. ``` targets: typescript: publish: jsr: package_name: "@/" ``` Create a JSR package 1. Log in or sign up at [JSR](https://jsr.io/). 2. Select **Publish a package**. 3. Choose an appropriate scope and package name. 4. Select **Create**. Get an access token 1. In JSR, navigate to **Account** > **Tokens** > **Personal access tokens** > **Create new token**. 2. Navigate through wizard to get your token: 1. **Publish packages** 2. **A development machine** 3. **Create a token** 4. Create a token for the package name. Add the token to your production repo 1. In your production repo, navigate to **Secrets and variables** > **Actions** > **New repository secret**. The URL should look like `https://github.com///settings/secrets/actions/new`. 2. Add a new secret named `JSR_TOKEN` with your API token. Update your Stainless config Update the [Stainless config](/docs/reference/config#typescript/index.md) with your package name and `use_access_token`, and save. ``` targets: typescript: package_name: publish: npm: true jsr: package_name: @/ use_access_token: true ``` ## Migrations Migrate from the Node target to TypeScript If you’re currently using the `node` target, you can migrate to the `typescript` target to benefit from zero dependencies and improved developer experience. The new TypeScript SDK generator uses built-in `fetch` instead of `node-fetch`. For more information on the changes, see the [changelog entry](https://www.stainless.com/changelog/typescript-sdk-generator-v2). ### Before migrating **Custom code conflicts** To avoid problems during the migration, make sure your Node SDK does not have any open conflict PRs. 1. Go to your project’s “Overview” page. 2. If you see an open conflict, resolve it first. See our [custom code documentation](/docs/guides/add-custom-code#merge-conflicts/index.md) for more details. ![Node SDK with custom code conflict](/docs/_astro/node-sdk-with-conflict.BLR-KdLP_2f3PTM.webp) Example of a Node SDK with a custom code conflict **Production repositories** You will need to decide whether you want to reuse your Node SDK’s prod repo as-is, rename it (e.g. from `my-node-sdk` to `my-typescript-sdk`), or create a new repo (to make it easier to refer to the previous version’s source code). - If you’d like to keep the same prod repo and name, no action is needed and you may continue with the migration steps. - If you’re reusing the existing prod repo, but would like to rename it (e.g., from `my-node-sdk` to `my-typescript-sdk`), first complete the migration steps, then rename the GitHub repo and update the `production_repo` key in your Stainless config. - If you’d prefer to create a new production repo, do so before migrating. ### Migration steps 1. Note the current version of your `node` SDK from its `package.json`. 2. Choose a new version number. This is a breaking change, so if you have released a v1 you’ll need to bump the major version (e.g., v1.x.x → v2.0.0). 3. In your Stainless config, add a new `typescript` target: ``` targets: node: # <-- Your existing node target package_name: my-sdk production_repo: my-org/my-sdk-node publish: npm: true typescript: # <-- The new typescript target package_name: my-sdk # Same name as for node production_repo: null # Don't set the prod repo yet publish: npm: false options: node_migration: # These values will be used in the generated migration guide previous_version: '1' # Last version number before migration migrated_version: '2' # New version number for the `typescript` SDK ``` 4. Save and build. A new staging repository named `-typescript` will be created. 5. Review the `MIGRATION.md` file generated in the typescript staging repo and ensure everything looks correct. 6. Update the `typescript` target to use the prod repo, set the `publish.npm` flag to `true`, and remove the `node` target. If you prefer to keep the node target in your config, set its `production_repo` to `null`. Be sure to not trigger a new build when both `node` and `typescript` targets have the same `production_repo` value. ``` targets: typescript: package_name: my-sdk production_repo: my-org/my-sdk-node # Updated prod repo publish: npm: true # Enabled NPM publishing options: node_migration: previous_version: '1' migrated_version: '2' ``` 7. Save and build. A release PR will be opened with the new `typescript` SDK and migration guide. If the version isn’t what you expected, [update the PR title](/docs/guides/publish#how-to-customize-the-release-version/index.md) to correct it. You’re all set! 🎉 Your SDK is now using our `typescript` SDK generator, with zero dependencies and an improved developer experience. If you have questions or run into issues, email us at .