r/OpenSourceeAI • • Apr 16 '26

I built a CLI that shrinks OpenAPI specs by 90%+ before feeding them to LLMs — open source

Hey everyone! I’ve been frustrated by how much context window gets wasted when you paste an OpenAPI/Swagger spec into an AI assistant. A single endpoint can take 80+ lines of verbose JSON, and a full API spec can eat your entire prompt budget.

So I built apidocs2ai — a CLI tool that converts OpenAPI/Swagger specs into a compact, AI-optimized format called LAPIS (Lightweight API Specification).

Real-world token reductions:

•	Petstore: 84.8% reduction

•	GitHub API: 82.7% reduction

•	DigitalOcean: 90.8% reduction

•	Twilio: 92.1% reduction

How it looks in practice:

Instead of 80+ lines of JSON for one endpoint, you get:

```

GET /pet/{petId}

petId: int (path, required)

-> 200: Pet

```

Usage is dead simple:

```

npx apidocs2ai openapi.yaml

# or from a URL

apidocs2ai https://petstore3.swagger.io/api/v3/openapi.json

```

It also supports Markdown and JSON output formats, piping from stdin, clipboard copy, and a --json flag for structured output that AI agents can parse programmatically. Swagger 2.0 is auto-upgraded to OpenAPI 3.0.

Works great with Claude Code, ChatGPT, or any LLM — just pipe or paste the output.

GitHub: https://github.com/guibes/apidocs2ai

npm: npm install -g apidocs2ai

Still early (v0.1.1), so feedback and contributions are very welcome. Would love to hear if anyone finds edge cases or has ideas for the LAPIS format!

12 Upvotes

8 comments sorted by

2

u/scotty2012 Apr 20 '26

I’ve been doing something like this with various token heavy file formats like sheets, pdfs, etc:

https://github.com/os-tack/repositories?q=fcp

1

u/Current-Slip-9173 Apr 21 '26

I want make something like your project, but with connector for any file, if you want we can make something together

1

u/Electronic-Medium931 Apr 18 '26

I like the idea, but what about openapi-to-markdown or widdershins? Whats the benefit of your solution?

1

u/Current-Slip-9173 Apr 18 '26

The main advantage is token reduction. Markdown still carries a lot of structural noise: headers, separators, descriptive text, that adds no value for an LLM processing an API. It was designed for humans to read. LAPIS was designed specifically for AIs, so every character has a purpose.

1

u/Clustered_Guy Apr 18 '26

This is actually super useful. OpenAPI specs are brutal to work with in prompts, half the context gets wasted on structure instead of meaning.

I like how readable the output is, it’s not just compressed, it’s actually easier to reason about. That’s usually the hard part with these tools.

One thing I’d be curious about is how you handle edge cases like deeply nested schemas or optional fields that matter for certain endpoints. That’s where most simplifications tend to lose important detail.

But yeah, reducing tokens while keeping it usable for agents is a solid direction, this solves a very real pain.

1

u/Current-Slip-9173 Apr 18 '26

The project is still in its early stages, so if you have more complex examples, run into any issues, or have ideas for improvement, feel free to open an issue on GitHub. You can read more about LAPIS here https://arxiv.org/html/2602.18541v1

2

u/ximihoque Apr 17 '26

publish it in Claude plugins, will make the adoption even faster