---
title: "Auth and Parameters | Micdrop"
description: "Handle user authentication and custom parameters in your voice server for secure and personalized conversations."
url: "https://micdrop.dev/docs/server/auth-and-parameters"
---

*   [Getting Started](/docs/getting-started)
*   [Client (Browser)](/docs/client)
    
    *   [Installation](/docs/client/installation)
    *   [React Hooks](/docs/client/react-hooks)
    *   [Start/Stop Call](/docs/client/start-stop-call)
    *   [Pause/Resume Call](/docs/client/pause-resume-call)
    *   [Mute/Unmute Call](/docs/client/mute-unmute-call)
    *   [Call State](/docs/client/call-state)
    *   [Display Conversation Messages](/docs/client/display-conversation-messages)
    *   [Handling Tool Calls](/docs/client/handling-tool-calls)
    *   [Device Management](/docs/client/devices-management)
    *   [Voice Activity Detection (VAD)](/docs/client/vad)
    *   [Error Handling](/docs/client/error-handling)
    *   Utility Classes
        
        *   [Mic](/docs/client/utility-classes/mic)
        *   [MicdropClient](/docs/client/utility-classes/micdrop-client)
        *   [MicRecorder](/docs/client/utility-classes/mic-recorder)
        *   [Speaker](/docs/client/utility-classes/speaker)
        
    
*   [Server (Node.js)](/docs/server)
    
    *   [Installation](/docs/server/installation)
    *   [With Fastify](/docs/server/with-fastify)
    *   [With NestJS](/docs/server/with-nestjs)
    *   [Auth and Parameters](/docs/server/auth-and-parameters)
    *   [First Message](/docs/server/first-message)
    *   [Save Messages](/docs/server/save-messages)
    *   [Resume a Conversation](/docs/server/resume-conversation)
    *   [Recording Audio](/docs/server/recording-audio)
    *   [Error Handling](/docs/server/error-handling)
    *   [Tools](/docs/server/tools)
    *   [Extract Value from Answer](/docs/server/extract)
    *   [Auto End Call](/docs/server/auto-end-call)
    *   [Semantic Turn Detection](/docs/server/semantic-turn-detection)
    *   [Noise Filtering](/docs/server/noise-filtering)
    *   [Micdrop Protocol](/docs/server/protocol)
    
*   [AI Integrations](/docs/ai-integration)
    
    *   Provided Integrations
        
        *   [AI SDK](/docs/ai-integration/provided-integrations/ai-sdk)
        *   [Cartesia](/docs/ai-integration/provided-integrations/cartesia)
        *   [ElevenLabs](/docs/ai-integration/provided-integrations/elevenlabs)
        *   [Gladia](/docs/ai-integration/provided-integrations/gladia)
        *   [Gradium](/docs/ai-integration/provided-integrations/gradium)
        *   [Mistral](/docs/ai-integration/provided-integrations/mistral)
        *   [OpenAI](/docs/ai-integration/provided-integrations/openai)
        
    *   Custom Integrations
        
        *   [Agent (LLM)](/docs/ai-integration/custom-integrations/custom-agent)
        *   [Speech-to-Text (STT)](/docs/ai-integration/custom-integrations/custom-stt)
        *   [Text-to-Speech (TTS)](/docs/ai-integration/custom-integrations/custom-tts)
        
    *   Fallback Strategies
        
        *   [FallbackAgent](/docs/ai-integration/fallback-strategies/agent-fallback)
        *   [FallbackSTT](/docs/ai-integration/fallback-strategies/stt-fallback)
        *   [FallbackTTS](/docs/ai-integration/fallback-strategies/tts-fallback)
        
    *   [IA Vocale Souveraine 🇫🇷🇪🇺](/docs/ai-integration/sovereign-voice-ai)
    

[Micdrop](/) › [Documentation](/docs/getting-started)

# Auth and Parameters

Handle user authentication and custom parameters in your voice server for secure and personalized conversations.

## Basic Parameter Handling

Use `waitForParams` to receive and validate client parameters:

```
import { MicdropServer, waitForParams, handleError } from '@micdrop/server'import { z } from 'zod'
// Define parameter schemaconst paramsSchema = z.object({  language: z.string().oneOf(['en', 'fr']).default('en'),})
wss.on('connection', async (socket) => {  try {    // Wait for parameters from client    const params = await waitForParams(socket, paramsSchema.parse)
    console.log('Client params:', params)
    // Use parameters to configure agent    const agent = new OpenaiAgent({      apiKey: process.env.OPENAI_API_KEY,      systemPrompt: `Respond in ${params.language} language`,    })
    // Setup STT and TTS [...]
    // Start MicdropServer    new MicdropServer(socket, { agent, stt, tss })  } catch (error) {    handleError(socket, error)  }})
```

## Authentication Examples

### JWT Token Validation

```
import {  MicdropServer,  MicdropError,  MicdropErrorCode,  waitForParams,  handleError,} from '@micdrop/server'import jwt from 'jsonwebtoken'import { z } from 'zod'
async function validateJWT(token: string) {  try {    const decoded = jwt.verify(token, process.env.JWT_SECRET)    return { isValid: true, user: decoded }  } catch (error) {    return { isValid: false, error: error.message }  }}
const paramsSchema = z.object({  authorization: z.string().startsWith('Bearer '),})
wss.on('connection', async (socket) => {  try {    const params = await waitForParams(socket, paramsSchema.parse)
    // Validate JWT token    const token = params.authorization.replace('Bearer ', '')    const auth = await validateJWT(token)
    if (!auth.isValid) {      throw new MicdropError(MicdropErrorCode.Unauthorized, 'Invalid JWT token')    }
    // Use authenticated user data    console.log('Authenticated user:', auth.user)
    // Setup AI components [..]
    // Start MicdropServer    new MicdropServer(socket, { agent, stt, tts })  } catch (error) {    handleError(socket, error)  }})
```

### API Key Authentication

```
import {  MicdropServer,  MicdropError,  MicdropErrorCode,  waitForParams,  handleError,} from '@micdrop/server'import { z } from 'zod'
const validApiKeys = new Set([process.env.API_KEY_1, process.env.API_KEY_2])
const paramsSchema = z.object({  apiKey: z.string(),})
wss.on('connection', async (socket) => {  try {    const params = await waitForParams(socket, paramsSchema.parse)
    // Validate API key    if (!validApiKeys.has(params.apiKey)) {      throw new MicdropError(MicdropErrorCode.Unauthorized, 'Invalid API key')    }
    // Setup AI components [..]
    // Start MicdropServer    new MicdropServer(socket, { agent, stt, tts })  } catch (error) {    handleError(socket, error)  }})
```

[Previous← With NestJS](/docs/server/with-nestjs)[NextFirst Message →](/docs/server/first-message)

On this page

*   [Basic Parameter Handling](#basic-parameter-handling)
*   [Authentication Examples](#authentication-examples)
*   [JWT Token Validation](#jwt-token-validation)
*   [API Key Authentication](#api-key-authentication)
