SDK Generator
An autonomous skill that discovers API surfaces from live websites or HAR archives, plans
SDK functions with LLM-assisted review, generates typed SDKs in multiple languages with
full test suites, validates everything end-to-end, and manages the entire lifecycle through
Git — including continuous updates when the upstream API changes.
Quick Reference
| Phase |
What Happens |
Reference |
| Discovery |
Crawl site or parse HAR to find endpoints |
references/discovery.md |
| Planning |
Design SDK functions, get LLM peer review |
references/planning.md |
| Generation |
Implement SDK code per language target |
references/generation.md |
| Testing |
Unit tests, mocks, e2e validation, auto-fix |
references/testing.md |
| Git Workflow |
Branching, commits, PRs, versioning |
references/git-workflow.md |
| Update Cycle |
Re-crawl, diff, patch, re-test |
references/update-cycle.md |
Prerequisites
Before starting, verify the following tools are available:
# Required
git --version
python3 --version
node --version
npm --version
# Install if missing
pip install requests httpx pydantic pytest pytest-asyncio respx --break-system-packages
npm install -g typescript jest ts-jest @types/jest axios
# Optional: for browser-based login during authenticated discovery
pip install playwright --break-system-packages
playwright install chromium
Workflow Overview
Phase 0: Initialize Project
- Create the SDK repository structure (see
references/repo-structure.md)
- Initialize Git with
main branch and proper .gitignore
- Set up language-specific project scaffolding (pyproject.toml, package.json, etc.)
- Create initial commit:
chore: initialize SDK project scaffold
Phase 1: API Discovery
Read references/discovery.md and agents/discovery.md for the full procedure.
Two entry paths, same output:
Path A — Live Website:
- Accept a base URL from the user
- Resolve authentication credentials (see below)
- Use browser automation or HTTP crawling to navigate the site
- Intercept and record all API calls (XHR/fetch requests)
- Capture: method, URL pattern, headers, query params, request body, response body, status codes
- Identify authentication patterns (Bearer tokens, API keys, cookies, OAuth flows)
Path B — HAR Archive:
- Accept a .har file from the user
- Parse all entries, filtering to API-like requests (JSON responses, REST patterns)
- Extract the same data points as Path A
- Detect auth patterns from captured headers, then redact all sensitive values
- Group by logical endpoint (normalize URL path parameters)
Authentication: If the target site requires authentication, credentials can be
provided through multiple channels (see agents/discovery.md for full details):
| Method |
Example |
| Inline in prompt |
Crawl https://app.example.com with bearer token: "eyJ..." |
| Environment variables |
SDK_GEN_AUTH_TOKEN, SDK_GEN_AUTH_COOKIE, SDK_GEN_AUTH_HEADER_NAME/VALUE |
| Browser login (Playwright) |
Agent opens a browser, user or automation completes login, agent extracts session |
| MCP browser server |
If available, use browser MCP tools for login and credential extraction |
For OAuth/SSO flows that require user interaction (consent screens, MFA), the agent
launches a visible browser window and guides the user through the login. After login
completes, session cookies and tokens are extracted automatically.
Inline credentials take precedence over env vars. Browser login is used as a fallback
when no static credentials are available.
Output: An api-surface.json file containing every discovered endpoint with:
- Method + URL pattern (with path params identified like
/users/{id})
- Request/response schemas (inferred JSON schemas)
- Required headers and auth patterns (with credential values redacted)
- Observed status codes and error shapes
- Pagination patterns if detected
Phase 2: Function Planning
Read references/planning.md for the full procedure.
This is the most critical phase. Every API endpoint becomes a planned SDK function.
Generate the plan: For each endpoint in api-surface.json, produce:
- Function name (language-idiomatic:
snake_case for Python, camelCase for TS/JS)
- Parameter list with types (inferred from request schema)
- Return type (inferred from response schema)
- Error handling strategy
- Whether it needs pagination support
- Mock/stub specification for testing
LLM Peer Review: The plan is reviewed by a second LLM call acting as a senior
API design reviewer. The reviewer checks for:
- Naming consistency and idiomaticness
- Missing error cases
- Type safety gaps
- Pagination/retry patterns that should be included
- Authentication flow correctness
- Breaking the plan into logical resource groupings (e.g.,
users.*, projects.*)
The review produces a structured critique with approve, suggest, or reject
verdicts per function. All reject items must be addressed before proceeding.
suggest items should be addressed but can be deferred with justification.
Finalize: Merge review feedback into the plan. Save as sdk-plan.json.
Git: Commit the plan on a feature branch:
git checkout -b feat/initial-sdk-plan
git add api-surface.json sdk-plan.json
git commit -m "docs: add API surface discovery and SDK function plan"
Phase 3: SDK Generation
Read references/generation.md for the full procedure.
For each target language, generate the SDK from the approved plan:
Models/Types: Generate typed data classes / interfaces from response schemas
Client Class: Base HTTP client with auth, retry, error handling
Resource Modules: Group functions by resource (users, projects, etc.)
Each Function: Implement according to the plan — typed params, return types,
docstrings, error handling, pagination wrappers where needed
Mocks & Stubs: For every function, generate:
- A mock response factory (returns realistic fake data matching the schema)
- A request stub that validates the outgoing request shape
- A fixture file with sample payloads
Git: Each resource module is committed separately:
git add python/src/promptql/users.py python/tests/test_users.py python/tests/mocks/users.py
git commit -m "feat(python): add users resource with tests and mocks"
Phase 4: Testing
Read references/testing.md for the full procedure.
Testing happens in two layers, and bugs are fixed automatically:
Layer 1 — Unit Tests (offline):
- Every SDK function has unit tests using mocks/stubs
- Tests validate: correct HTTP method/URL, proper serialization of params,
correct deserialization of responses, error handling paths
- Run:
pytest python/tests/ and npx jest for TypeScript
- If any test fails → read the error → fix the code → re-run → repeat until green
Layer 2 — End-to-End Tests (if live endpoint available):
- For each function, make a real API call (if safe — GET endpoints, read-only operations)
- Validate response matches expected schema
- Capture any discrepancies as schema refinements
- Run:
pytest python/tests/e2e/ with --e2e flag
- If any e2e test fails → diagnose whether it's an SDK bug or a schema inaccuracy →
fix accordingly → re-run → repeat until green
Auto-fix loop:
MAX_FIX_ATTEMPTS = 5
for attempt in range(MAX_FIX_ATTEMPTS):
result = run_tests()
if result.all_passed:
break
for failure in result.failures:
diagnose(failure)
apply_fix(failure)
git commit -m "fix: {description of what was fixed}"
If after MAX_FIX_ATTEMPTS tests still fail, create a GitHub issue or TODO comment
and continue with remaining endpoints. Do not block the entire SDK on one stubborn test.
Git: After all tests pass:
git add .
git commit -m "test: all unit and e2e tests passing"
git checkout main
git merge feat/initial-sdk-plan --no-ff -m "feat: initial SDK release"
git tag v0.1.0
Phase 5: Update Cycle
Read references/update-cycle.md for the full procedure.
When the user triggers an update (or on a schedule):
- Re-discover: Run Phase 1 again, producing
api-surface-new.json
- Diff: Compare against the existing
api-surface.json:
- New endpoints → plan + review + generate + test (mini Phase 2-4)
- Changed endpoints (new fields, changed types) → update types + functions + tests
- Removed endpoints → deprecate functions, add
@deprecated decorators, update tests
- Branch:
feat/api-update-YYYY-MM-DD
- Plan new/changed functions with LLM review (same as Phase 2)
- Generate/update code with full test suite
- Run all tests (existing + new) — auto-fix loop
- Merge + tag: Bump version appropriately (minor for additions, major for breaking changes)
Multi-Language Support
The skill generates SDKs for these targets by default (user can customize):
| Language |
Directory |
Package Manager |
Test Framework |
| Python |
python/ |
pip / pyproject.toml |
pytest |
| TypeScript |
typescript/ |
npm / package.json |
jest |
Additional languages can be added by creating a new generation template
in templates/ and adding the language config to sdk-plan.json.
Error Handling Philosophy
- Never block on a single failure. If one endpoint's tests can't be fixed after
MAX_FIX_ATTEMPTS, mark it as
status: broken in the plan, commit what works,
and move on.
- Always commit working state. Every commit should leave the repo in a state
where existing tests pass.
- Surface unknowns. If the discovery phase can't determine a type or pattern,
use the most permissive type (
Any / unknown) and add a TODO comment.
Coordinator Responsibilities
The agent orchestrating this skill must:
- Follow phases in order — Discovery → Planning → Generation → Testing → Git finalize
- Never skip LLM review — The planning review catches design mistakes early
- Commit atomically — Each logical unit of work gets its own commit
- Run the full test suite before merging — No merge without green tests
- Preserve the API surface file — This is the source of truth for diffing on updates
- Use conventional commits —
feat:, fix:, test:, docs:, chore: prefixes
- Tag releases — SemVer: patch for fixes, minor for new endpoints, major for breaking changes
1---2name: sdk-generator3description: Autonomous SDK generator that discovers API endpoints from a live website or HAR archive, plans and builds typed SDKs in multiple languages, and continuously updates them as the API evolves. Use this skill whenever the user wants to reverse-engineer an API, generate client SDKs from observed traffic, build API wrappers from HAR files, create typed clients from web service exploration, or keep an SDK in sync with a changing API. Also trigger when the user mentions "SDK generation", "API client from HAR", "reverse engineer API", "auto-generate SDK", "crawl API and build client", or any variation of turning observed HTTP traffic into usable code libraries.4---5
6# SDK Generator
7
8An autonomous skill that discovers API surfaces from live websites or HAR archives, plans
9SDK functions with LLM-assisted review, generates typed SDKs in multiple languages with
10full test suites, validates everything end-to-end, and manages the entire lifecycle through
11Git — including continuous updates when the upstream API changes.
12
13## Quick Reference
14
15| Phase | What Happens | Reference |
16|-------|-------------|-----------|
17| **Discovery** | Crawl site or parse HAR to find endpoints | `references/discovery.md` |
18| **Planning** | Design SDK functions, get LLM peer review | `references/planning.md` |
19| **Generation** | Implement SDK code per language target | `references/generation.md` |
20| **Testing** | Unit tests, mocks, e2e validation, auto-fix | `references/testing.md` |
21| **Git Workflow** | Branching, commits, PRs, versioning | `references/git-workflow.md` |
22| **Update Cycle** | Re-crawl, diff, patch, re-test | `references/update-cycle.md` |
23
24---
25
26## Prerequisites
27
28Before starting, verify the following tools are available:
29
30```bash
31# Required
32git --version
33python3 --version
34node --version
35npm --version
36
37# Install if missing
38pip install requests httpx pydantic pytest pytest-asyncio respx --break-system-packages
39npm install -g typescript jest ts-jest @types/jest axios
40
41# Optional: for browser-based login during authenticated discovery
42pip install playwright --break-system-packages
43playwright install chromium
44```
45
46---
47
48## Workflow Overview
49
50### Phase 0: Initialize Project
51
521. Create the SDK repository structure (see `references/repo-structure.md`)
532. Initialize Git with `main` branch and proper `.gitignore`
543. Set up language-specific project scaffolding (pyproject.toml, package.json, etc.)
554. Create initial commit: `chore: initialize SDK project scaffold`
56
57### Phase 1: API Discovery
58
59Read `references/discovery.md` and `agents/discovery.md` for the full procedure.
60
61Two entry paths, same output:
62
63**Path A — Live Website:**
641. Accept a base URL from the user
652. Resolve authentication credentials (see below)
663. Use browser automation or HTTP crawling to navigate the site
674. Intercept and record all API calls (XHR/fetch requests)
685. Capture: method, URL pattern, headers, query params, request body, response body, status codes
696. Identify authentication patterns (Bearer tokens, API keys, cookies, OAuth flows)
70
71**Path B — HAR Archive:**
721. Accept a .har file from the user
732. Parse all entries, filtering to API-like requests (JSON responses, REST patterns)
743. Extract the same data points as Path A
754. Detect auth patterns from captured headers, then redact all sensitive values
765. Group by logical endpoint (normalize URL path parameters)
77
78**Authentication:** If the target site requires authentication, credentials can be
79provided through multiple channels (see `agents/discovery.md` for full details):
80
81| Method | Example |
82|--------|---------|
83| Inline in prompt | `Crawl https://app.example.com with bearer token: "eyJ..."` |
84| Environment variables | `SDK_GEN_AUTH_TOKEN`, `SDK_GEN_AUTH_COOKIE`, `SDK_GEN_AUTH_HEADER_NAME`/`VALUE` |
85| Browser login (Playwright) | Agent opens a browser, user or automation completes login, agent extracts session |
86| MCP browser server | If available, use browser MCP tools for login and credential extraction |
87
88For OAuth/SSO flows that require user interaction (consent screens, MFA), the agent
89launches a visible browser window and guides the user through the login. After login
90completes, session cookies and tokens are extracted automatically.
91
92Inline credentials take precedence over env vars. Browser login is used as a fallback
93when no static credentials are available.
94
95**Output:** An `api-surface.json` file containing every discovered endpoint with:
96- Method + URL pattern (with path params identified like `/users/{id}`)
97- Request/response schemas (inferred JSON schemas)
98- Required headers and auth patterns (with credential values redacted)
99- Observed status codes and error shapes
100- Pagination patterns if detected
101
102### Phase 2: Function Planning
103
104Read `references/planning.md` for the full procedure.
105
106This is the most critical phase. Every API endpoint becomes a planned SDK function.
107
1081. **Generate the plan:** For each endpoint in `api-surface.json`, produce:
109 - Function name (language-idiomatic: `snake_case` for Python, `camelCase` for TS/JS)
110 - Parameter list with types (inferred from request schema)
111 - Return type (inferred from response schema)
112 - Error handling strategy
113 - Whether it needs pagination support
114 - Mock/stub specification for testing
115
1162. **LLM Peer Review:** The plan is reviewed by a second LLM call acting as a senior
117 API design reviewer. The reviewer checks for:
118 - Naming consistency and idiomaticness
119 - Missing error cases
120 - Type safety gaps
121 - Pagination/retry patterns that should be included
122 - Authentication flow correctness
123 - Breaking the plan into logical resource groupings (e.g., `users.*`, `projects.*`)
124
125 The review produces a structured critique with `approve`, `suggest`, or `reject`
126 verdicts per function. All `reject` items must be addressed before proceeding.
127 `suggest` items should be addressed but can be deferred with justification.
128
1293. **Finalize:** Merge review feedback into the plan. Save as `sdk-plan.json`.
130
1314. **Git:** Commit the plan on a feature branch:
132 ```
133 git checkout -b feat/initial-sdk-plan
134 git add api-surface.json sdk-plan.json
135 git commit -m "docs: add API surface discovery and SDK function plan"
136 ```
137
138### Phase 3: SDK Generation
139
140Read `references/generation.md` for the full procedure.
141
142For each target language, generate the SDK from the approved plan:
143
1441. **Models/Types:** Generate typed data classes / interfaces from response schemas
1452. **Client Class:** Base HTTP client with auth, retry, error handling
1463. **Resource Modules:** Group functions by resource (users, projects, etc.)
1474. **Each Function:** Implement according to the plan — typed params, return types,
148 docstrings, error handling, pagination wrappers where needed
1495. **Mocks & Stubs:** For every function, generate:
150 - A mock response factory (returns realistic fake data matching the schema)
151 - A request stub that validates the outgoing request shape
152 - A fixture file with sample payloads
153
1546. **Git:** Each resource module is committed separately:
155 ```
156 git add python/src/promptql/users.py python/tests/test_users.py python/tests/mocks/users.py
157 git commit -m "feat(python): add users resource with tests and mocks"
158 ```
159
160### Phase 4: Testing
161
162Read `references/testing.md` for the full procedure.
163
164Testing happens in two layers, and bugs are fixed automatically:
165
166**Layer 1 — Unit Tests (offline):**
167- Every SDK function has unit tests using mocks/stubs
168- Tests validate: correct HTTP method/URL, proper serialization of params,
169 correct deserialization of responses, error handling paths
170- Run: `pytest python/tests/` and `npx jest` for TypeScript
171- If any test fails → read the error → fix the code → re-run → repeat until green
172
173**Layer 2 — End-to-End Tests (if live endpoint available):**
174- For each function, make a real API call (if safe — GET endpoints, read-only operations)
175- Validate response matches expected schema
176- Capture any discrepancies as schema refinements
177- Run: `pytest python/tests/e2e/` with `--e2e` flag
178- If any e2e test fails → diagnose whether it's an SDK bug or a schema inaccuracy →
179 fix accordingly → re-run → repeat until green
180
181**Auto-fix loop:**
182```
183MAX_FIX_ATTEMPTS = 5
184for attempt in range(MAX_FIX_ATTEMPTS):
185 result = run_tests()
186 if result.all_passed:
187 break
188 for failure in result.failures:
189 diagnose(failure)
190 apply_fix(failure)
191 git commit -m "fix: {description of what was fixed}"
192```
193
194If after MAX_FIX_ATTEMPTS tests still fail, create a GitHub issue or TODO comment
195and continue with remaining endpoints. Do not block the entire SDK on one stubborn test.
196
197**Git:** After all tests pass:
198```
199git add .
200git commit -m "test: all unit and e2e tests passing"
201git checkout main
202git merge feat/initial-sdk-plan --no-ff -m "feat: initial SDK release"
203git tag v0.1.0
204```
205
206### Phase 5: Update Cycle
207
208Read `references/update-cycle.md` for the full procedure.
209
210When the user triggers an update (or on a schedule):
211
2121. **Re-discover:** Run Phase 1 again, producing `api-surface-new.json`
2132. **Diff:** Compare against the existing `api-surface.json`:
214 - **New endpoints** → plan + review + generate + test (mini Phase 2-4)
215 - **Changed endpoints** (new fields, changed types) → update types + functions + tests
216 - **Removed endpoints** → deprecate functions, add `@deprecated` decorators, update tests
2173. **Branch:** `feat/api-update-YYYY-MM-DD`
2184. **Plan new/changed functions** with LLM review (same as Phase 2)
2195. **Generate/update code** with full test suite
2206. **Run all tests** (existing + new) — auto-fix loop
2217. **Merge + tag:** Bump version appropriately (minor for additions, major for breaking changes)
222
223---
224
225## Multi-Language Support
226
227The skill generates SDKs for these targets by default (user can customize):
228
229| Language | Directory | Package Manager | Test Framework |
230|----------|-----------|----------------|----------------|
231| Python | `python/` | pip / pyproject.toml | pytest |
232| TypeScript | `typescript/` | npm / package.json | jest |
233
234Additional languages can be added by creating a new generation template
235in `templates/` and adding the language config to `sdk-plan.json`.
236
237---
238
239## Error Handling Philosophy
240
241- **Never block on a single failure.** If one endpoint's tests can't be fixed after
242 MAX_FIX_ATTEMPTS, mark it as `status: broken` in the plan, commit what works,
243 and move on.
244- **Always commit working state.** Every commit should leave the repo in a state
245 where existing tests pass.
246- **Surface unknowns.** If the discovery phase can't determine a type or pattern,
247 use the most permissive type (`Any` / `unknown`) and add a `TODO` comment.
248
249---
250
251## Coordinator Responsibilities
252
253The agent orchestrating this skill must:
254
2551. **Follow phases in order** — Discovery → Planning → Generation → Testing → Git finalize
2562. **Never skip LLM review** — The planning review catches design mistakes early
2573. **Commit atomically** — Each logical unit of work gets its own commit
2584. **Run the full test suite before merging** — No merge without green tests
2595. **Preserve the API surface file** — This is the source of truth for diffing on updates
2606. **Use conventional commits** — `feat:`, `fix:`, `test:`, `docs:`, `chore:` prefixes
2617. **Tag releases** — SemVer: patch for fixes, minor for new endpoints, major for breaking changes