Skip to main content
Technical Deep DiveD2 API Quality

Auto-Generated SDKs: How OpenAPI Specs Let AI Agents Write Their Own Client Libraries

When a business publishes an OpenAPI spec, AI agents do not need your documentation. They do not need your SDK. They generate their own in whatever language they are running — in seconds. The spec is the documentation, the contract, and the source code all in one file.

AH
AgentHermes Research
April 15, 202613 min read

The Shift: From “We Publish an SDK” to “Agents Generate Their Own”

For decades, the API lifecycle followed a predictable pattern. You built the API, wrote documentation, then published SDKs in the top 3-5 languages your customers used. Python, JavaScript, Go, Java, maybe Ruby. Each SDK was hand-maintained, versioned separately, and updated weeks after the API itself changed.

AI agents break this model completely. An agent does not wait for your SDK team. It reads your OpenAPI specification, runs it through a code generator, and produces a typed client library in whatever language it needs — Python, Rust, Go, TypeScript, Swift — in under 10 seconds. No human involvement. No support ticket. No waiting for the next quarterly SDK release.

This is not theoretical. Stripe uses Stainless to generate its official SDKs from its OpenAPI spec. Vercel and Mistral use Speakeasy. The open-source openapi-generator project supports 50+ languages. The tools exist. The agents know how to use them. The only question is whether your business publishes a spec for them to consume.

50+
Languages supported
0.15
D2 API weight (highest)
<10s
SDK generation time
85%
Of 500 lack OpenAPI

How Agents Generate SDKs from OpenAPI Specs

The workflow is straightforward. An agent encounters a new API it needs to interact with. Instead of reading documentation pages designed for humans, it looks for a machine-readable spec. Here is what happens next.

1

Agent discovers the OpenAPI spec

The agent checks standard locations: /openapi.json, /openapi.yaml, /api/openapi, or the link in agent-card.json. If the business publishes a spec at any of these paths, the agent finds it automatically.

2

Agent validates the spec

A quick validation pass confirms the spec is valid OpenAPI 3.x, checks for required fields (paths, schemas, securitySchemes), and identifies available endpoints. Invalid specs get rejected here.

3

Agent runs the generator

The agent invokes openapi-generator (or equivalent) targeting its runtime language. For a Python agent: openapi-generator generate -i spec.json -g python -o ./client. Ten seconds later, a typed client exists.

4

Agent uses the generated SDK

The generated client has typed methods for every endpoint, handles authentication per the securitySchemes, serializes requests, and deserializes responses. The agent calls client.list_products() instead of crafting raw HTTP requests.

5

Agent handles errors with typed exceptions

Error responses defined in the spec become typed exception classes. The agent catches ProductNotFoundError instead of parsing raw 404 bodies. Retry logic, rate limiting, and pagination are handled by the SDK layer.

The Three SDK Generation Tools Agents Use

Three tools dominate the SDK generation landscape. Each serves a different use case, but all produce the same outcome: a typed client library from an OpenAPI spec.

openapi-generator

The open-source workhorse. Supports 50+ languages. Community-maintained templates. Any agent running locally can invoke it from the CLI to generate a typed client from any OpenAPI spec in seconds.

Strength: Broadest language support — 50+ targets including Python, TypeScript, Go, Rust, Java, C#, Ruby, Swift, and Kotlin.

Limitation: Generated code can be verbose. Templates require maintenance. No automatic publishing to package registries.

Speakeasy

Commercial SDK generator focused on developer experience. Produces idiomatic SDKs that feel hand-written. Used by Vercel, Mistral, and Codat. Auto-publishes to npm, PyPI, and other registries.

Strength: Idiomatic output — generated Python reads like Python, generated TypeScript reads like TypeScript. Auto-versioning and CI/CD integration.

Limitation: Commercial license. Requires a Speakeasy account. Less flexible for custom templating than openapi-generator.

Stainless

The tool Stripe uses to generate its official SDKs. Also used by OpenAI, Cloudflare, and Lithic. Produces production-grade SDKs with pagination helpers, retry logic, and streaming support built in.

Strength: Production-grade output with retries, pagination, and streaming. The gold standard for API companies.

Limitation: Enterprise-focused. Not open source. Designed for API-first companies, not general-purpose use.

With OpenAPI Spec vs Without: What Agents Experience

The difference between a business that publishes an OpenAPI spec and one that does not is the difference between a paved road and a dirt trail.

Aspect
With OpenAPI Spec
Without Spec
Discovery
Agent reads openapi.json, knows every endpoint
Agent scrapes HTML docs, guesses parameters
SDK Generation
openapi-generator creates typed client in seconds
Agent writes raw HTTP calls, hopes for the best
Type Safety
Every request/response has a typed schema
Runtime errors from wrong parameter types
Error Handling
Error responses defined in spec, SDK handles them
Agent parses HTML error pages
Versioning
SDK pins to API version, upgrades cleanly
Breaking changes crash the agent silently
Auth
securitySchemes tell agent exactly how to authenticate
Agent guesses between API key, Bearer, Basic

Businesses without an OpenAPI spec force agents to screen-scrape HTML documentation pages. The agent has to parse natural language descriptions, guess parameter names and types, and hope the examples on the docs page are accurate. It is fragile, slow, and error-prone. Any agent that has a choice between a business with a spec and one without will choose the spec every time.

Impact on Your Agent Readiness Score

D2 API Quality carries a 0.15 weight — the highest of any single dimension in the Agent Readiness Score. It is the dimension most directly impacted by whether you publish an OpenAPI spec.

AgentHermes checks for: published OpenAPI/Swagger spec, valid schema definitions, documented endpoints with descriptions, defined securitySchemes, and response schema coverage. A business with a complete OpenAPI spec typically scores 15-20 points higher on D2 than one relying on HTML documentation alone.

But the downstream effects go further. An OpenAPI spec also improves D3 Onboarding (agents can self-serve), D6 Data Quality (typed responses), and D9 Agent Experience (structured error handling). The single act of publishing a spec ripples across four of nine dimensions.

D2 API Quality (0.15)

Direct impact. OpenAPI spec presence is the single strongest signal. Companies with published specs average 72 on D2. Companies without average 31.

D3 Onboarding (0.08)

Agents use the spec to self-onboard. securitySchemes tell them how to authenticate. No human handholding required.

D6 Data Quality (0.10)

Response schemas in the spec define exactly what structured data agents receive. No guessing, no parsing HTML.

D9 Agent Experience (0.10)

Error schemas, pagination definitions, and example values in the spec make agent interactions predictable and recoverable.

The bottom line: Publishing an OpenAPI spec is the single highest-leverage action a business can take to improve its Agent Readiness Score. It directly impacts 43% of the total score weight (D2 + D3 + D6 + D9). If you do one thing after reading this article, publish your spec at /openapi.json.

Case Study: How Stripe Uses Stainless for SDK Generation

Stripe maintains a comprehensive OpenAPI spec with over 300 endpoints. Instead of manually maintaining SDKs in 7 languages, they use Stainless to generate production-grade SDKs from that spec. Every SDK gets pagination helpers, automatic retries with exponential backoff, streaming support, and idiomatic error handling — all derived from the spec.

This is why Stripe scores 68 Silver on Agent Readiness. An agent interacting with Stripe does not need to read docs.stripe.com. It reads the OpenAPI spec, generates a typed client, and starts making API calls with full type safety. The spec tells the agent everything: endpoints, parameters, authentication (Bearer token via securitySchemes), error formats, and pagination cursors.

OpenAI, Cloudflare, and Lithic follow the same pattern. The API-first companies that dominate the Silver tier all treat the OpenAPI spec as the source of truth — not the documentation site, not the hand-written SDKs. The spec generates everything else.

How to Make Your API SDK-Generation Ready

Publishing an OpenAPI spec that agents can use for SDK generation takes an afternoon. Here is the checklist.

Serve your OpenAPI 3.x spec at /openapi.json (or /openapi.yaml). CORS-enabled.

Define all endpoints with operationId, summary, and description fields.

Add request body schemas with property types, descriptions, and required markers.

Define response schemas for 200, 400, 401, 404, and 500 status codes.

Include securitySchemes — Bearer, API key, or OAuth 2.0 client_credentials.

Add example values to parameters and response properties.

Reference your spec from agent-card.json and llms.txt for discovery.

For businesses already using frameworks like FastAPI, NestJS, or Spring Boot, the OpenAPI spec is often auto-generated from code annotations. The only step is making it publicly accessible. For businesses with custom APIs, tools like the MCP server tutorial show how to create both the spec and the agent-native interface in a single build session.

Frequently Asked Questions

Can AI agents really generate SDKs automatically?

Yes. An AI agent with access to openapi-generator (or any SDK generation tool) can read an OpenAPI spec, run the generator for any target language, and produce a fully typed client library. The agent does not need to understand your API beforehand — the spec provides complete information about endpoints, parameters, authentication, and response schemas.

Does my OpenAPI spec need to be perfect for SDK generation to work?

It needs to be valid, not perfect. The generator will produce a working SDK from any valid OpenAPI 3.x spec. However, better specs produce better SDKs. Adding descriptions to parameters, using meaningful operation IDs, and defining all response schemas will make the generated SDK more usable. A minimal valid spec is still far better than no spec at all.

How does SDK generation affect my Agent Readiness Score?

SDK generation itself is not directly scored, but the OpenAPI spec that enables it is. D2 API Quality (weighted 0.15 — the highest single dimension) checks for a published OpenAPI spec, valid schema definitions, and documented endpoints. A business with a published OpenAPI spec typically scores 15-20 points higher on D2 than one without.

What if I already publish SDKs manually?

Manual SDKs are valuable but limited. You publish SDKs in 3-5 languages. An agent with your OpenAPI spec can generate one in any of 50+ languages in seconds. The spec is the universal source. Think of manual SDKs as a bonus on top of the spec, not a replacement for it. Stripe publishes both — official SDKs via Stainless AND a complete OpenAPI spec.


Is your API ready for agent-generated SDKs?

Run a free Agent Readiness Scan to see your D2 API Quality score and whether agents can discover your OpenAPI spec.


Share this article: