customize-sdk-hooks

Implement BeforeRequest, AfterSuccess, and AfterError hooks in generated SDKs.

19|6|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/speakeasy-api/skills --skill customize-sdk-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: customize-sdk-hooks
Source: https://github.com/speakeasy-api/skills/tree/main/skills/customize-sdk-hooks
Command: npx skills add https://github.com/speakeasy-api/skills --skill customize-sdk-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables developers to inject custom logic into generated SDKs by implementing lifecycle hooks, enabling advanced customization without altering API specs.

Core Features & Use Cases

  • Configure and implement BeforeRequest, AfterSuccess, and AfterError hooks to modify requests, transform responses, and capture telemetry.
  • Add custom headers, signing, or middleware logic in the SDK without touching generated code each cycle.
  • Use cases include injecting correlation IDs, custom authentication headers, and per-operation telemetry for observability.

Quick Start

  1. Ensure you have a Speakeasy-generated SDK with a src/hooks directory.
  2. Create a new hook implementation file under src/hooks/ (e.g., custom_headers.ts) that implements the appropriate hook interface.
  3. Register your hook in src/hooks/registration.ts and regenerate the SDK with the Speakeasy CLI.
  4. Call your SDK as usual and verify the hooks execute during the request lifecycle.

Frequently Asked Questions about customize-sdk-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add custom headers and telemetry to an SDK without modifying generated code?

You can add custom headers and telemetry to an SDK by implementing BeforeRequest, AfterSuccess, and AfterError hooks. These lifecycle hooks allow you to inject custom logic like header modification and telemetry capture without altering generated code each cycle.

How do I implement HMAC signing in SDK requests using lifecycle hooks?

Implement HMAC signing in SDK requests by creating a hook implementation file that adheres to the BeforeRequest interface. Register this hook in the SDK's registration file to ensure your custom signing logic executes during the request lifecycle and survives regenerations.

Does my generated SDK need specific directories to support custom hooks?

Yes, custom hooks require your Speakeasy-generated SDK to contain a src/hooks/ directory and a registration.ts file. You must place new hook implementations under src/hooks/ and wire them through registration.ts before regenerating the SDK with the CLI.

Can I inject correlation IDs and custom authentication into API requests with SDK hooks?

Yes, you can inject correlation IDs and custom authentication headers into API requests using BeforeRequest hooks. This allows you to configure custom middleware logic across multiple languages directly within the SDK lifecycle.

Will my custom SDK hooks be preserved when I regenerate the SDK?

Yes, custom hook implementations are preserved across SDK regenerations. As long as your hooks adhere to the defined interfaces and are registered in the src/hooks/registration.ts file, they will remain intact during the request lifecycle.

What is the best way to capture per-operation observability data in an SDK?

The best way to capture per-operation observability data is by using AfterSuccess and AfterError hooks. These lifecycle hooks enable you to capture telemetry and transform responses during SDK usage without touching the underlying API specs.