---
title: Code samples
subtitle: Every endpoint gets request examples in 9 languages automatically; use x-codeSamples to replace them or add your own SDK examples.
description: Code samples in the ButterIX API reference — auto-generated cURL, Python, TypeScript, Go, Ruby, Java, PHP, C#, and Swift examples, x-codeSamples language matching, language sync, and filtering example languages in guides.
---

## Auto-generated examples

From an endpoint's method, server URL, path parameters, query parameters, headers, authentication scheme, and request body example, ButterIX generates request code in these languages for every endpoint:

| id | Label | Notes |
|---|---|---|
| `curl` | cURL | Command line |
| `python` | Python | `requests` |
| `javascript` | TypeScript | `fetch` |
| `go` | Go | `net/http` |
| `ruby` | Ruby | `net/http` |
| `java` | Java | `java.net.http.HttpClient` |
| `php` | PHP | Guzzle |
| `csharp` | C# | `HttpClient` |
| `swift` | Swift | `URLSession` |

When a reader switches language on an example card, every API example and code group on the site switches to the same language, and the choice is remembered on the next visit.

<EndpointRequestSnippet endpoint="POST /orgs/{org}/sites" />

## Choose which languages to show

All nine are shown by default. List the languages to show, in order, with `code-languages` in `docs.yml`; anything not listed is hidden:

```yaml title="docs.yml"
code-languages: [curl, python, typescript, go]
```

- Use an `id` from the table above or an alias (such as `typescript`, `golang`, `c#`). Adding `payload` gives an extra entry with just the request data.
- The request examples on endpoint pages and the **Try it** panel use the same list.
- In the console: **Docs settings → API reference → Code example languages** in the editor.

## Provide your own examples with x-codeSamples

If you have an official SDK, you usually want to show SDK usage instead of raw HTTP requests. Add `x-codeSamples` to the operation (a Redocly convention; `x-code-samples` works too):

```yaml title="openapi.yml" {6-16}
paths:
  /payments:
    post:
      summary: Create a payment
      x-fern-sdk-method-name: create-payment
      x-codeSamples:
        - lang: typescript
          label: Node SDK
          source: |
            const payment = await acme.payments.create({ amount: 1999, currency: "cny" });
        - lang: python
          label: Python SDK
          source: |
            payment = acme.Payment.create(amount=1999, currency="cny")
        - lang: console
          label: Acme CLI
          source: |
            $ acme payments create --amount 1999 --currency cny
```

Matching rules:

- When `lang` maps to a built-in language, it **replaces** that language's generated example and the label becomes `label`. Aliases: `shell` / `bash` / `sh` → cURL, `typescript` / `ts` / `js` / `node` → TypeScript, `py` → Python, `golang` → Go, `rb` → Ruby, `c#` / `cs` → C#.
- A `lang` that doesn't map to a built-in language (like `console` above) is **appended** as an extra tab at the end, and `lang` is also used as the highlighting language.
- If you write several examples for the same language, only the last one takes effect.

This site's [Create deployment](/api-reference/deployments/create-deployment) endpoint demonstrates both cases: a `shell` example replaces the generated cURL, and a `console` example is appended as a "biti CLI" tab at the end.

<EndpointRequestSnippet endpoint="POST /sites/{site}/deployments" />

## Filter languages in guides

The `languages` prop on `<EndpointRequestSnippet>` sets which languages appear and in what order; adding `payload` adds a tab that shows only the request body JSON:

```mdx
<EndpointRequestSnippet
  endpoint="PUT /sites/{site}/ai"
  example="deepseek"
  languages={["curl", "python", "payload"]}
/>
```

<EndpointRequestSnippet endpoint="PUT /sites/{site}/ai" example="deepseek" languages={["curl", "python", "payload"]} />

`example` selects an entry from the spec's `examples` by name (or `summary`); the example above selects the request example named `deepseek`.

## Values in examples

| Location | Value |
|---|---|
| Base URL | The first entry of operation-level `servers` → path-level `servers` → top-level `servers` (with server variables replaced by their defaults) |
| Path parameters, required query parameters, and headers | The parameter's `example` / `examples` → schema example (optional query parameters and headers are omitted) |
| Authentication | Bearer schemes produce `Authorization: Bearer <token>`; API key schemes go into a header or query parameter based on `in` |
| Request body | The first entry in `examples` (or the selected `example`) → `example` → generated from the schema (required fields only) |

<Tip>
  Give schema fields realistic `example` values and the generated examples become much more readable. This site's spec does exactly that with `name: { type: string, example: Acme 文档 }`.
</Tip>
