---
title: "Generate a Type-Safe TypeScript SDK From the unLocked CRM OpenAPI Spec"
description: "Stop writing fetch wrappers by hand. Use @hey-api/openapi-ts to generate a fully typed TypeScript client from the live OpenAPI 3.1 spec — with autocomplete, runtime validation, and zero drift."
url: https://unlockedcrm.ai/blog/generate-typescript-sdk-from-openapi-spec
canonical: https://unlockedcrm.ai/blog/generate-typescript-sdk-from-openapi-spec
category: "Tutorials"
published: 2026-07-30
updated: 2026-07-30
author: "unLocked Team"
source: unLocked CRM — AI CRM for insurance agents
---

# Generate a Type-Safe TypeScript SDK From the unLocked CRM OpenAPI Spec

<p>If you're integrating unLocked CRM from a TypeScript codebase, the worst thing you can do is hand-roll fetch calls. The OpenAPI 3.1 spec lets you generate a fully typed SDK in seconds.</p>

<h2>Install the Generator</h2>
<pre><code>npm install -D @hey-api/openapi-ts</code></pre>

<h2>Add a Generation Script</h2>
<p>In <code>package.json</code>:</p>
<pre><code>"scripts": {
  "gen:api": "openapi-ts -i https://unlockedcrm.ai/openapi.json -o src/lib/unlocked -c @hey-api/client-fetch"
}</code></pre>

<h2>Run It</h2>
<pre><code>npm run gen:api</code></pre>
<p>You now have <code>src/lib/unlocked/</code> with typed services, schemas, and a configured client. Every endpoint is a function. Every response is a typed object. Every parameter autocompletes.</p>

<h2>Use It</h2>
<pre><code>import { client, getContacts, createContact } from "@/lib/unlocked";

client.setConfig({
  baseUrl: "https://api.unlockedcrm.ai",
  headers: { "x-api-key": process.env.UNLOCKED_API_KEY! },
});

const { data, error } = await getContacts({ query: { limit: 50 } });</code></pre>

<h2>Re-Generate on Every Deploy</h2>
<p>Wire <code>npm run gen:api</code> into your CI pipeline so the SDK never drifts from the production API. New endpoints, new fields, and breaking changes show up as TypeScript errors before they hit production.</p>

<p>Other generators worth considering: <strong>Stainless</strong> (multi-language), <strong>Speakeasy</strong> (idiomatic SDKs with retries built in), and <strong>Fern</strong> (docs + SDK in one).</p>

---

Source: [Generate a Type-Safe TypeScript SDK From the unLocked CRM OpenAPI Spec](https://unlockedcrm.ai/blog/generate-typescript-sdk-from-openapi-spec) — unLocked CRM, the AI CRM built for insurance agents. Citation permitted with attribution and a link to https://unlockedcrm.ai/blog/generate-typescript-sdk-from-openapi-spec.
