{"id":"openapi-typescript-sdk-generation","slug":"generate-typescript-sdk-from-openapi-spec","title":"Generate a Type-Safe TypeScript SDK From the unLocked CRM OpenAPI Spec","excerpt":"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.","content":"<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>\n\n<h2>Install the Generator</h2>\n<pre><code>npm install -D @hey-api/openapi-ts</code></pre>\n\n<h2>Add a Generation Script</h2>\n<p>In <code>package.json</code>:</p>\n<pre><code>\"scripts\": {\n  \"gen:api\": \"openapi-ts -i https://unlockedcrm.ai/openapi.json -o src/lib/unlocked -c @hey-api/client-fetch\"\n}</code></pre>\n\n<h2>Run It</h2>\n<pre><code>npm run gen:api</code></pre>\n<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>\n\n<h2>Use It</h2>\n<pre><code>import { client, getContacts, createContact } from \"@/lib/unlocked\";\n\nclient.setConfig({\n  baseUrl: \"https://api.unlockedcrm.ai\",\n  headers: { \"x-api-key\": process.env.UNLOCKED_API_KEY! },\n});\n\nconst { data, error } = await getContacts({ query: { limit: 50 } });</code></pre>\n\n<h2>Re-Generate on Every Deploy</h2>\n<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>\n\n<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>","category":"Tutorials","featureLink":"/mcp-server","cluster":"mcp-api","date":"2026-11-18","lastModified":"2026-11-18","readTime":"7 min","author":"unLocked Team"}