Skip to main content

GitBook

GitBook is a documentation platform that makes it easy to build centralized documentation sites and collaborate on authoring docs.

With the Stainless <> GitBook integration, you can:

  1. Generate robust and polished SDKs directly from your OpenAPI spec.
  2. Embed language-specific code samples into your GitBook docs.
  3. Keep docs and SDKs automatically in sync as your API evolves.

JavaScript code example rendered by GitBook API docs

This integration bridges the gap between documentation and implementation, giving developers copy-paste-ready examples that demonstrate your API in action.

Prerequisites

Before starting, make sure you have:

  • An account on Stainless
  • An existing GitBook documentation site
  • Your OpenAPI specification

1. Create Your SDKs in the Studio

  1. Log in to the Stainless dashboard
  2. Click "New Project" and upload your OpenAPI specification
  3. Stainless will analyze your API and create an initial SDK configuration

The SDK Studio provides an immediate preview of your SDK structure based on your API's resources, methods, and models.

Stainless SDK Studio showing SDK preview

When first created, Stainless organizes your API into logical resources, but the exact names and hierarchy is up to you, allowing you to create the most intuitive experience for your users.

The Studio lets you customize everything from resource naming to authentication schemes - dive into the configuration guide to learn how to prepare SDKs developers will love.

2. Generate Code Examples

In the Studio, add the following to your Stainless configuration file:

openapi:
code_samples: 'gitbook'

This tells Stainless to create a copy of your OpenAPI file extended with SDK code examples, in a format GitBook can render. For advanced integration options and support for other documentation platforms, explore the documentation integration guide.

3. Publish the URL to your OpenAPI spec

Go to your Stainless project page, select the "Release" tab, and select "Setup OpenAPI publishing."

Publishing your documented OpenAPI spec

Turn the OpenAPI publishing toggle on. This will create a stable publicly accessible URL for your OpenAPI spec which can be used by GitBook. This OpenAPI spec is enriched with Stainless SDK code samples in the x-code-samples field.

The URL is stable and will always stay up-to-date with the latest information about your SDKs.

Finally, click the "copy" button next to the URL.

4. Add your OpenAPI spec to GitBook

Now that you have a URL pointing to your documented OpenAPI, the last step is to add it to GitBook:

  1. In your GitBook editor, open the OpenAPI panel.
  2. Add a new OpenAPI spec, and paste the OpenAPI URL into the API Reference block's “OpenAPI URL” field.
  3. Save your spec, and in a new space, generate an OpenAPI reference from your newly added spec.

GitBook will fetch the spec, render your API reference, and include the Stainless-generated code samples for supported languages. Head to GitBook's guide on publishing API documentation for a full feature overview.

By combining Stainless's SDK generation with GitBook's documentation capabilities, you're providing developers with a seamless experience from discovery to implementation.