Silgi

Hey API

Convert Hey API generated OpenAPI clients into Silgi-compatible clients.

Convert a Hey API generated client into a Silgi client to use it with the full Silgi ecosystem — TanStack Query, Pinia Colada, and other integrations.

Hey API is still in an unstable stage. This integration may introduce breaking changes in the future.

Setup

Generate a Hey API client

Use @hey-api/openapi-ts to generate a typed client from your OpenAPI spec:

npx @hey-api/openapi-ts \
  -i https://api.example.com/api/openapi.json \
  -o src/client

This outputs the generated SDK into the src/client directory.

For more information on Hey API, see the official documentation.

Convert to a Silgi client

import {  } from 'silgi/hey-api'
import * as  from './client/sdk.gen'

export const  = ()

The client now behaves like any standard Silgi client — you can use it with TanStack Query, Pinia Colada, or call procedures directly.

Use the client

// Direct calls
const {  } = await client.listPlanets()
.() // Planet[]

// With query params
const { body:  } = await client.getPlanet({
  : { : 'earth' },
})

// With request body
const { body:  } = await client.createPlanet({
  : { : 'Mars' },
})

Each call returns { body, request, response } where:

PropertyTypeDescription
bodyTThe parsed response data
requestRequestThe original Request object
responseResponseThe raw Response for headers/status

With TanStack Query

Combine with createQueryUtils for full query/mutation support:

import {  } from 'silgi/hey-api'
import {  } from 'silgi/tanstack-query'
import * as  from './client/sdk.gen'

const  = ()
const  = ()

// Now use with useQuery, useMutation, etc.
const  = .listPlanets.queryOptions({ : {} })

With Pinia Colada

import {  } from 'silgi/hey-api'
import {  } from 'silgi/pinia-colada'
import * as  from './client/sdk.gen'

const  = ()
const  = ()

Error handling

Internally, Silgi passes throwOnError: true to the Hey API client. If the original Hey API client throws an error, it is forwarded as-is without modification.

try {
  const {  } = await client.getPlanet({ : { : 'unknown' } })
} catch () {
  // Error from Hey API — same format as the original SDK
  .()
}

Abort signals

Abort signals are supported from both the input and the client options:

const  = new ()

// From input
const  = await client.listPlanets({
  : .,
})

// From client options
const  = await client.listPlanets(
  {},
  {
    : .,
  },
)

// Either signal aborting will cancel the request
.()

What's next?

  • Client — learn about Silgi clients
  • TanStack Query — use the converted client with TanStack Query
  • Pinia Colada — use the converted client with Pinia Colada
  • OpenAPI Client — alternative: consume OpenAPI specs directly with OpenAPILink

On this page