Skip to content

ButterIX v1 is out: versions, multiple languages, Ask AI, and a per-site MCP server, all built in. →

Code samples

Every endpoint gets request examples in 9 languages automatically; use x-codeSamples to replace them or add your own SDK examples.

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:

idLabelNotes
curlcURLCommand line
pythonPythonrequests
javascriptTypeScriptfetch
goGonet/http
rubyRubynet/http
javaJavajava.net.http.HttpClient
phpPHPGuzzle
csharpC#HttpClient
swiftSwiftURLSession

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.

POST/orgs/:org/sites
curl -X POST https://api.butterix.com/v1/orgs/acme/sites \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "name": "Acme Docs",
         "slug": "acme-payments",
         "template": "starter"
       }'

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:

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):

openapi.yml
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 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.

POST/sites/:site/deployments
tar --exclude=node_modules --exclude=.git --exclude=dist -czf site.tgz .
curl -X POST https://api.butterix.com/v1/sites/acme-payments/deployments \
  -H "Authorization: Bearer $BITI_TOKEN" \
  -H "Content-Type: application/gzip" \
  -H "x-biti-preview: 1" \
  --data-binary @site.tgz

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:

<EndpointRequestSnippet
  endpoint="PUT /sites/{site}/ai"
  example="deepseek"
  languages={["curl", "python", "payload"]}
/>
PUT/sites/:site/ai
curl -X PUT https://api.butterix.com/v1/sites/acme-payments/ai \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "provider": "deepseek",
         "model": "deepseek-flash",
         "apiKey": "sk-xxxxxxxxxxxxxxxx"
       }'

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

LocationValue
Base URLThe 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 headersThe parameter's example / examples → schema example (optional query parameters and headers are omitted)
AuthenticationBearer schemes produce Authorization: Bearer <token>; API key schemes go into a header or query parameter based on in
Request bodyThe first entry in examples (or the selected example) → example → generated from the schema (required fields only)

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 文档 }.