useRuntimeConfig()

Accesses runtime configuration values, with server-only secrets and public keys.

Since Nuxt 3.0 Spec ↗

Syntax

const config = useRuntimeConfig()

Returns

RuntimeConfig — Object with private root keys (server only) and a public sub-object.

Examples

<script setup lang="ts">
const config = useRuntimeConfig()
// Only public.* is available on the client
const apiBase = config.public.apiBase
</script>
// server/api/secret.ts — private keys available here
export default defineEventHandler(() => {
  const config = useRuntimeConfig()
  return $fetch('https://api.example.com', {
    headers: { Authorization: `Bearer ${config.apiSecret}` },
  })
})
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    apiSecret: '',
    public: { apiBase: '/api' },
  },
})

Notes

Private (root-level) values are only available on the server; only `public.*` is sent to the client. Defaults come from `runtimeConfig` in `nuxt.config`; they can be overridden at runtime via `NUXT_*` environment variables. In server routes prefer the `event`-bound `useRuntimeConfig(event)` so per-request env overrides apply.

See also