hai-api-client

Initialize a type-safe HTTP client with automatic token refresh and Zod validation.

3|7|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/hai-series/hai-framework --skill hai-api-client
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hai-api-client
Source: https://github.com/hai-series/hai-framework/tree/main/packages/cli/templates/skills/hai-api-client
Command: npx skills add https://github.com/hai-series/hai-framework --skill hai-api-client

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Solves the need for a unified, type-safe HTTP client across web and mobile apps by providing a singleton api object, automatic token handling, and contract-driven calls.

Core Features & Use Cases

  • Unified API access across platforms via api.init and api.call with EndpointDef contracts.
  • Automatic Bearer token management, including storage, attachment, and refresh retries.
  • Streaming support (SSE / ReadableStream) and strong runtime validation with Zod.

Quick Start

Initialize the client at app startup with baseUrl and auth settings, then perform authenticated requests using api.call with a typed EndpointDef.

Frequently Asked Questions about hai-api-client

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

FAQPage Schema
How do I manage HTTP API tokens and automatically refresh them in TypeScript?

To manage HTTP API tokens and automatically refresh them, you can use a unified TypeScript HTTP client that handles Bearer token storage, attachment, and automatic refresh retries during contract-driven API calls.

What is the best way to create a type-safe HTTP client for Web and mobile apps?

A type-safe HTTP client for Web and mobile apps uses a singleton object initialized via api.init, combining Zod-based runtime validation with EndpointDef contracts to enforce consistent API usage across platforms.

How do I handle streaming responses like SSE in a type-safe API client?

To handle streaming responses in a type-safe API client, you need a client that supports SSE and ReadableStream protocols alongside strong runtime validation, ensuring data structure integrity during continuous data fetching.

Does this unified API client support Zod-based runtime validation for contract-driven calls?

Yes, this unified API client supports Zod-based runtime validation for contract-driven calls, allowing you to define typed EndpointDef contracts that validate request and response data structures automatically.

How do I initialize a singleton HTTP client with endpoint contracts at app startup?

To initialize a singleton HTTP client at app startup, configure it with baseUrl and authentication settings using the api.init method, then execute authenticated requests through api.call with your defined EndpointDef.

Why should I use contract-driven API calls instead of standard fetch requests?

Contract-driven API calls solve the problem of inconsistent API usage by enforcing type-safe EndpointDef structures and Zod validation, providing stronger runtime safety and unified access than standard fetch requests.