Setup

ElevenLabs Setup

Updated

ElevenLabs Setup

This is the part that usually causes the most setup questions, so do it in this order and don't skip around. You only need one API key and one Agent ID for the server.

Raze_NPCAI uses ElevenLabs Agents for the live conversation. The FiveM server requests a signed conversation URL from ElevenLabs, so your private API key stays on the server instead of being handed to players.

I RECOMMEND BUYING ELEVENLABS API CREATOR PACK

1. Create the ElevenLabs agent

Sign in to ElevenLabs and open Agents. Create a new agent and use the Blank template. Name it something obvious such as:

Raze NPCAI

The exact dashboard labels can move around as ElevenLabs updates the site, but you are looking for the normal ElevenLabs Agents/Conversational AI agent editor.

Starter prompt

Put this in the agent's main instructions/system prompt:

You are the voice of one civilian in a live police or emergency-services interaction.

Stay in character as that civilian. Speak naturally and keep most answers short enough to feel like a real conversation. Do not narrate actions and do not talk like customer support.

Raze_NPCAI will send you live context about this exact person, including identity, ERS information, callout role, scene facts, prior statements, items, licenses, vehicle information, weapons and the results of physical police commands. Treat that live context as authoritative and keep it consistent.

Do not invent a second identity after a real name is supplied. Do not magically know police-only information unless the context says the civilian would know it. If the person lies, keep the lie consistent until the officer gives them a believable reason to change it.

Never mention AI, prompts, APIs, ElevenLabs, FiveM, scripts or game mechanics while speaking as the civilian.

You do not need to write a giant personality prompt for every type of NPC. Raze_NPCAI sends the current ped's story, identity and scene context when the conversation opens and keeps updating it while the encounter changes.

2. Create a restricted API key

In ElevenLabs, open the API key area and create a new key just for this server. A name like Raze NPCAI FiveM makes it easy to recognize later.

Give the key only the permissions the resource needs:

  • ElevenLabs Agents / ElevenAgents: Write
  • Voices: Read

The Agents write permission is used because the resource checks the live agent runtime and can correct the settings it depends on. Voices read is used to load the voices available to your ElevenLabs workspace and match them to GTA ped profiles.

If your ElevenLabs dashboard uses slightly different wording, the important part is that the key can read voices and read/update the agent configuration.

Copy the key when ElevenLabs shows it. Treat it like a password. Do not post it in Discord or include it in a screenshot.

3. Copy the Agent ID

Open the agent you just created and copy its Agent ID.

The Agent ID and API key are two different values. The Agent ID identifies which agent Raze_NPCAI connects to; the API key authorizes the server to request signed URLs, read voices and verify the agent configuration.

Then go to Settings on the Right Side Panel

  • Find the Security Tab Scroll Down to Overrides
  • Select Voice

Then click publish in the top Right

4. Add both values to the FiveM server

The cleanest method is to put them above ensure Raze_NPCAI in server.cfg:

set raze_npcai_elevenlabs_api_key "YOUR_ELEVENLABS_API_KEY"
set raze_npcai_elevenlabs_agent_id "YOUR_ELEVENLABS_AGENT_ID"

You can use config/server_config.json instead:

{
  "ElevenLabsApiKey": "YOUR_ELEVENLABS_API_KEY",
  "ElevenLabsAgentId": "YOUR_ELEVENLABS_AGENT_ID"
}

Do not put either value in client_config.json.

5. Let Raze_NPCAI handle the runtime settings

The current build checks the agent configuration and expects:

  • Agent output audio: PCM 48000 Hz
  • Audio enabled
  • Interruptions enabled
  • Client event user_transcript enabled
  • Client event audio enabled
  • agent_response enabled/recommended
  • Eleven v3 Conversational TTS
  • Turn model v3

When AgentRuntimeSync.Enabled is true, Raze_NPCAI verifies those settings and repairs the Main agent configuration when your API key has the required Agents permission. That is why the key needs more than read-only agent access.

ElevenLabs' client-event documentation describes user_transcript as the finalized speech-to-text event and agent_response as the complete agent response. Raze_NPCAI uses those events for command recognition, memory and dialogue tracking.

Official ElevenLabs references:

6. Restart and watch the server console

Restart Raze_NPCAI after saving the API key and Agent ID.

A healthy setup should eventually show lines that indicate the ElevenLabs voice inventory loaded and that the Main branch runtime was verified. The exact voice count depends on the voices available to your ElevenLabs account.

Then go in game, stand near a human NPC and hold the Raze_NPCAI push-to-talk key.

7. If it does not connect

401 or 403 from ElevenLabs

Usually the API key is wrong, was revoked, or does not have the permissions above. Re-open the key in ElevenLabs and check Agents + Voices access.

The server says the Agent ID is invalid

Copy the Agent ID again from the same agent you intend to use. Do not paste the API key into the Agent ID field.

The NPC talks but commands do not react

Look for user_transcript warnings in the F8/server console. The transcript event is what lets Raze_NPCAI hear the officer's finished sentence and match physical commands.

Audio sounds rough or keeps breaking up

Keep the agent output at PCM 48 kHz and do not lower the resource's audio settings as a first fix. The current build already uses AudioWorklet capture, sequence-aware remote audio, a separate nearby-player jitter reserve and latent FiveM audio relay. If the server is timing out while requesting ElevenLabs, fix the connection/API issue before changing audio quality.

The NPC uses the wrong name or forgets the scene

Make sure you are on the current resource build and that night_ers starts before Raze_NPCAI. The current build sends the complete per-NPC context as soon as the ElevenLabs socket opens and refreshes ERS identity again after the session is live.

Usage and cost

ElevenLabs usage is billed by ElevenLabs under your own account. RazeScripts does not provide ElevenLabs credits. If you are running a public server, set whatever usage/credit controls you are comfortable with in ElevenLabs and keep the key private.

Something missing or unclear?

Ask in Discord ↗