Skip to content

ReadMe.io API Generation

This guide explains how to generate OpenPets-compatible tools from APIs hosted on ReadMe.io documentation platforms using the pets generate-readme CLI command.

Overview

Many popular APIs host their documentation on ReadMe.io (readme.com), which provides auto-generated API SDKs. The ReadMe generator uses the npx api install command to fetch OpenAPI specifications directly from the ReadMe registry, then delegates to the standard OpenAPI generator to create tools.

This approach is ideal for:

  • APIs with ReadMe.io-hosted documentation
  • Services that don't publicly expose their OpenAPI spec
  • Quick bootstrapping when you have the ReadMe registry ID

Quick Start

From Command Line

bash
cd pets/my-api

# Generate from ReadMe registry ID
pets generate-readme --registry "@luma-docs/v1.0#dem71tmjbssfr5"

# With verbose output
pets generate-readme --registry "@luma-docs/v1.0#dem71tmjbssfr5" -v

# Preview without writing files
pets generate-readme --registry "@luma-docs/v1.0#dem71tmjbssfr5" --dry-run

Add a readmeSpec section to your pet's package.json:

json
{
  "name": "@openpets/my-api",
  "readmeSpec": {
    "registryId": "@luma-docs/v1.0#dem71tmjbssfr5",
    "baseUrl": "https://public-api.luma.com",
    "authType": "apiKey",
    "apiKeyHeader": "x-luma-api-key",
    "authEnvVar": "LUMA_API_KEY"
  }
}

Then run:

bash
cd pets/my-api
pets generate-readme

Finding the Registry ID

The registry ID is typically found in the API documentation's SDK section:

  1. Go to the API reference page (e.g., https://docs.service.com/reference)
  2. Look for "API SDK", "Client Libraries", or similar sections
  3. Find the npx api install command - the argument is your registry ID

Registry ID format: @{org}-docs/{version}#{hash}

Examples:

  • @luma-docs/v1.0#dem71tmjbssfr5 (Luma Events API)
  • @readme-docs/v2.0#abc123xyz (ReadMe API)

Configuration Reference

package.json readmeSpec

PropertyTypeRequiredDescription
registryIdstringYesReadMe registry ID (e.g., "@luma-docs/v1.0#abc123")
baseUrlstringNoBase URL for API calls
altBaseUrlstringNoAlternative base URL for environment switching
baseUrlEnvVarstringNoEnvironment variable to select base URL
baseUrlEnvValuestringNoValue that triggers altBaseUrl
authEnvVarstringNoEnvironment variable for auth token/key
authSecretEnvVarstringNoEnvironment variable for auth secret
authTypestringNoAuthentication type: bearer, apiKey, basic, or none
apiKeyHeaderstringNoHeader name for API key auth
includestring[]NoOnly generate tools matching these patterns
excludestring[]NoSkip tools matching these patterns
readOnlyPatternsstring[]NoMark tools matching these patterns as read-only
coreEndpointsobjectNoConfigure which tools are core vs loadEnv

CLI Options

bash
pets generate-readme [options]

Options:
  --registry <id>       ReadMe.io registry ID
  --output <file>       Output file name (default: openapi-client.ts)
  --temp-dir <path>     Temp directory for api install (default: /tmp/readme-api-temp)
  --keep-temp           Keep temp directory after generation
  -n, --dry-run         Preview without writing files
  -v, --verbose         Show detailed output

How It Works

  1. Fetch spec: Runs npx api install {registryId} --lang ts in a temp directory
  2. Extract spec: Copies the OpenAPI spec from .api/apis/{project}/openapi.json
  3. Configure: Merges readmeSpec settings into openapiSpec in package.json
  4. Generate: Delegates to pets generate-openapi for tool generation

Real-World Example: Luma

The pets/luma pet demonstrates ReadMe API generation:

Finding the Registry ID

  1. Visit https://docs.lu.ma/reference/
  2. Look for the SDK installation section
  3. Find: npx api install "@luma-docs/v1.0#dem71tmjbssfr5"

package.json Configuration

json
{
  "name": "@openpets/luma",
  "readmeSpec": {
    "registryId": "@luma-docs/v1.0#dem71tmjbssfr5",
    "baseUrl": "https://public-api.luma.com",
    "authType": "apiKey",
    "apiKeyHeader": "x-luma-api-key",
    "authEnvVar": "LUMA_API_KEY",
    "coreEndpoints": {
      "tags": ["Events", "Calendars"],
      "paths": ["/v1/user/get-self", "/v1/event/get"]
    }
  }
}

Generation

bash
cd pets/luma
pets generate-readme -v

# Output:
# 🔧 Generating tools from ReadMe.io registry...
# ✅ Generated 42 tools (18 read-only, 24 write)
# 📁 Output: /path/to/pets/luma/openapi-client.ts
# 📄 OpenAPI spec: /path/to/pets/luma/openapi-spec.json
# 🔧 Tools generated: 42

Combining with openapiSpec

When you run pets generate-readme, it:

  1. Downloads the OpenAPI spec from ReadMe
  2. Saves it as openapi-spec.json in your pet directory
  3. Merges your readmeSpec settings into openapiSpec in package.json
  4. Generates tools using the standard OpenAPI generator

After generation, you can use pets generate-openapi directly for regeneration:

bash
# First time: use generate-readme to fetch the spec
pets generate-readme --registry "@luma-docs/v1.0#dem71tmjbssfr5"

# Future regenerations: use generate-openapi (faster, no network)
pets generate-openapi

Troubleshooting

"No registry ID provided"

Either:

  • Use --registry option: pets generate-readme --registry "@org/v1#hash"
  • Add readmeSpec.registryId to package.json

"api install failed"

Common causes:

  1. Invalid registry ID - verify the ID from the API docs
  2. Network issues - check your internet connection
  3. npm/npx not available - ensure Node.js is installed

Try with verbose mode:

bash
pets generate-readme --registry "@org/v1#hash" -v --keep-temp

"No openapi.json found"

The API install may have succeeded but created a different structure. Check:

bash
ls -la /tmp/readme-api-temp/.api/apis/

Authentication issues after generation

The ReadMe generator creates the OpenAPI spec file, but you still need to:

  1. Set up authentication in your .env file
  2. Configure authEnvVar and authType in your config

When to Use ReadMe vs OpenAPI Generation

ScenarioRecommended Approach
API has direct OpenAPI spec URLpets generate-openapi --url
API only on ReadMe.iopets generate-readme
Already have openapi-spec.jsonpets generate-openapi
First-time setup from ReadMepets generate-readme
Regenerating existing petpets generate-openapi

Supported ReadMe.io APIs

Any API documented on ReadMe.io with SDK generation enabled should work. Known working examples:

  • Luma (@luma-docs/v1.0#...) - Event management
  • ReadMe (@readme-docs/...) - Documentation API
  • Many others - check the API's reference docs for the registry ID