# Add SDK examples

> Add SDK code samples to your API documentation with the x-codeSamples OpenAPI extension or automatically with Speakeasy.

If your users interact with your API through an SDK rather than direct network requests, add SDK code samples with the `x-codeSamples` extension. Mintlify displays these samples on your OpenAPI pages.

You can write these samples yourself. If you generate your SDKs with Speakeasy, Speakeasy can add the samples to your spec automatically.

## Add examples manually

Add the `x-codeSamples` property to any request method. It has the following schema.

- `lang` (string, required) — The language of the code sample.

- `label` (string) — The label for the sample. This is useful when providing multiple examples for a single endpoint.

- `source` (string, required) — The source code of the sample.

The following example shows code samples for a plant tracking app that has both a Bash CLI tool and a JavaScript SDK.

```yaml theme={null}
paths:
  /plants:
    get:
      # ...
      x-codeSamples:
        - lang: bash
          label: List all unwatered plants
          source: |
            planter list -u
        - lang: javascript
          label: List all unwatered plants
          source: |
            const planter = require('planter');
            planter.list({ unwatered: true });
        - lang: bash
          label: List all potted plants
          source: |
            planter list -p
        - lang: javascript
          label: List all potted plants
          source: |
            const planter = require('planter');
            planter.list({ potted: true });
```

## Generate examples with Speakeasy

If you generate your SDKs with [Speakeasy](https://www.speakeasy.com), you can pull its autogenerated snippets into your API reference instead of maintaining them by hand. The snippets appear in the [interactive playground](/guides/document-apis-overview) alongside your endpoints.

:::::steps
::::step{title="Get the combined spec URL from the registry"}
Go to your [Speakeasy Dashboard](https://app.speakeasy.com) and open the **API Registry** tab. Open the `*-with-code-samples` entry for your API.

:::frame
![Screenshot of the Speakeasy API Registry page. A red square and the number 1 emphasize the API Registry tab, and a red square and the number 2 emphasize the entry for the API.](../img/site-assets/mintcdn.com/mintlify/f7fo9pnTEtzBD70_/images/speakeasy/openapi-registry-and-combined-spec-1hg9pw.png)
:::

:::callout{intent="note"}
If the entry is not labeled **Combined Spec**, ensure that your API has an [automated code sample URL](https://www.speakeasy.com/docs/code-samples/automated-code-sample-urls) configured.
:::

From the registry entry's page, copy the provided public URL.
::::

::::step{title="Add the combined spec URL to your `docs.json` file"}
Add the combined spec URL to an anchor or a tab in the `navigation` object of your `docs.json` file.

:::code-group
```json title="Anchor" theme={null}
{
  "navigation": {
    "anchors": [
      {
        "anchor": "API reference",
        "icon": "square-terminal",
        // !mark
        "openapi": "SPEAKEASY_COMBINED_SPEC_URL"
      }
    ]
  }
}
```

```json title="Tab" theme={null}
{
  "navigation": {
    "tabs": [
      {
        "tab": "API reference",
        // !mark
        "openapi": "SPEAKEASY_COMBINED_SPEC_URL"
      }
    ]
  }
}
```
:::
::::

:::step{title="Verify the integration"}
After you redeploy your documentation, open any endpoint in your API reference and confirm that language snippets appear in the playground. The set of available languages matches the SDK targets configured in your Speakeasy project.

If snippets do not appear, check that:

- The `openapi` URL in `docs.json` points to the `*-with-code-samples` combined spec entry, not the source OpenAPI file.
- The combined spec URL is publicly reachable from the browser.
- Your Speakeasy project has an [automated code sample URL](https://www.speakeasy.com/docs/code-samples/automated-code-sample-urls) configured and at least one SDK target enabled.
:::
:::::

## Related topics

- [Navigation](/docs/organize/navigation.md)
- [Examples](/guides/create-content-components-examples)
- [Fields](/guides/create-content-components-fields)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
