Speakeasy Code Samples APIReference
v0.4.0
OAS 3.0.3

Speakeasy Code Samples API

REST APIs for retrieving SDK usage snippets from the Speakeasy Code Samples API.

No authentication selected
Client Libraries

Retrieve usage snippets

Retrieve usage snippets from an OpenAPI document stored in the registry. Supports filtering by language and operation ID.

Query Parameters
  • registry_url
    string
    required

    The registry URL from which to retrieve the snippets.

  • operation_ids
    array string[]

    The operation IDs to retrieve snippets for.

  • method_paths
    array object[]

    The method paths to retrieve snippets for.

  • languages
    array string[]

    The languages to retrieve snippets for.

Responses
GET/v1/code_sample
import { SpeakeasyCodeSamples } from "@speakeasyapi/code-samples";

const speakeasyCodeSamples = new SpeakeasyCodeSamples({
  apiKey: "<YOUR_API_KEY_HERE>",
  registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

async function run() {
  const result = await speakeasyCodeSamples.codeSamples.get({
    registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
    operationIds: [
      "getPets",
    ],
    methodPaths: [
      {
        method: "get",
        path: "/pets",
      },
    ],
    languages: [
      "python",
      "javascript",
    ],
  });

  // Handle the result
  console.log(result);
}

run();
{
  "summary": "Array of usage snippets",
  "value": {
    "snippets": [
      {
        "operationId": "getPetById",
        "path": "/pet/{id}",
        "method": "get",
        "language": "typescript",
        "code": "import { Petstore } from \"petstore-sdk\";\n\nconst petstore = new Petstore({\n  apiKey: \"<YOUR_API_KEY_HERE>\",\n});\n\nasync function run() {\n  const result = await petstore.pet.getById({\n    id: 137396,\n  });\n\n  // Handle the result\n  console.log(result);\n}\n\nrun();"
      }
    ]
  }
}

Models