Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt

Use this file to discover all available pages before exploring further.

Eden is a client-side package. Install it in your frontend project alongside a dev dependency on Elysia itself — Eden needs the Elysia types to infer your server’s schema.

Install the package

bun add @elysia/eden
bun add -d elysia
The elysia dev dependency must match the version running on your server. Eden uses it only for type inference — it is never bundled into your frontend.

Export your server type

Add a single export type line to your Elysia server file. This is the only change required on the server side.
// server.ts
import { Elysia, t } from 'elysia'

const app = new Elysia()
    .get('/', () => 'Hi Elysia')
    .get('/id/:id', ({ params: { id } }) => id)
    .post('/mirror', ({ body }) => body, {
        body: t.Object({
            id: t.Number(),
            name: t.String()
        })
    })
    .listen(3000)

export type App = typeof app

Connect from the client

Import the exported type and pass it as a generic to treaty. TypeScript will infer every route, parameter type, and response type automatically.
// client.ts
import { treaty } from '@elysia/eden'
import type { App } from './server'

const client = treaty<App>('localhost:3000') 

// response: 'Hi Elysia'
const { data: index } = await client.get()

// response: '1895'
const { data: id } = await client.id({ id: 1895 }).get()

// response: { id: 1895, name: 'Skadi' }
const { data: nendoroid } = await client.mirror.post({
    id: 1895,
    name: 'Skadi'
})

Troubleshooting

If Eden isn’t picking up types correctly, work through these common causes in order.
Eden’s type inference requires TypeScript strict mode. Make sure your tsconfig.json includes:
{
  "compilerOptions": {
    "strict": true
  }
}
Both your frontend and server must use the same Elysia version. Check with:
npm why elysia
The output should show a single Elysia version at the top level. If you see multiple versions, align them in your package.json.
Eden uses TypeScript features like const generics and template literal types. You need TypeScript >= 5.0 on your client.
Elysia builds up its type incrementally through method chaining. Each method returns a new typed instance. If you break the chain, the types won’t propagate.
// ✅ correct — types are preserved through the chain
new Elysia()
    .state('build', 1)
    .get('/', ({ store: { build } }) => build)
    .listen(3000)
// ❌ incorrect — types are lost
const app = new Elysia()
app.state('build', 1)
app.get('/', ({ store: { build } }) => build)
app.listen(3000)
If your handlers return Bun-specific types like Bun.file, install @types/bun as a dev dependency on the client too:
bun add -d @types/bun
If your server uses TypeScript path aliases (e.g. @/controllers), your frontend’s tsconfig.json must be able to resolve those same paths. Otherwise Eden will infer any.Configure your root tsconfig.json to map each package with a namespace prefix:
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@frontend/*": ["./apps/frontend/src/*"],
      "@backend/*": ["./apps/backend/src/*"]
    }
  }
}
Then import the server type using the same alias:
import { treaty } from '@elysia/eden'
import type { app } from '@backend/index'

const client = treaty<app>('localhost:3000')

Build docs developers (and LLMs) love