apps/xai/grok-voice

grok-voice

Talk with Grok. Stream microphone audio over a socket and hear xAI's speech-to-speech model answer as it speaks, with both sides transcribed; the conversation is the task's output.

run with your agent
# install belt
$curl -fsSL https://cli.inference.sh | sh
# view schema & details
$belt app get xai/grok-voice
# run
$belt app run xai/grok-voice

api reference

about

talk with grok. stream microphone audio over a socket and hear xai's speech-to-speech model answer as it speaks, with both sides transcribed; the conversation is the task's output.

1. calling the api

install the client

the client provides a convenient way to interact with the api.

bash
1pip install inferencesh

setup your api key

set INFERENCE_API_KEY as an environment variable. get your key from settings → api keys.

bash
1export INFERENCE_API_KEY="inf_your_key"

run and get result

submit a request and wait for the final result. best for batch processing or when you don't need progress updates.

python
1from inferencesh import inference23client = inference()456result = client.run({7        "app": "xai/grok-voice",8        "input": {}9    })1011print(result["output"])

stream live updates

get real-time progress updates as the task runs. ideal for showing progress bars, partial results, or long-running tasks.

python
1from inferencesh import inference23client = inference()456# stream=True yields updates as they arrive7for update in client.run({8        "app": "xai/grok-voice",9        "input": {}10    }, stream=True):11    if update.get("progress"):12        print(f"progress: {update['progress']}%")13    if update.get("output"):14        print(f"output: {update['output']}")

2. authentication

the api uses api keys for authentication. see the authentication docs for detailed setup instructions.

3. files

file inputs are automatically handled by the sdk. you can pass local paths, urls, or base64 data.

automatic upload

the python sdk automatically detects local file paths and uploads them. urls are passed through as-is.

python
1# local file paths are automatically uploaded2result = client.run({3    "app": "xai/grok-voice",4    "input": {5        "image": "/path/to/local/image.png",  # detected & uploaded6        "audio": "https://example.com/audio.mp3",  # url passed through7    }8})

manual upload

you can also upload files manually and use the returned url.

python
1# upload and get a hosted URL2file = client.files.upload("/path/to/file.png")3print(file.uri)  # https://cloud.inference.sh/...

4. webhooks

get notified when a task completes by providing a webhook url. when the task reaches a terminal state (completed, failed, or cancelled), a POST request is sent to your url with the task result.

python
1result = client.run({2    "app": "xai/grok-voice",3    "input": {},4    "webhook": "https://your-server.com/webhook"5}, wait=False)

webhook payload

your endpoint receives a JSON POST with the task result:

json
1{2  "id": "task_abc123",3  "status": 9,4  "output": { ... },5  "error": "",6  "session_id": null,7  "created_at": "2024-01-15T10:30:00Z",8  "updated_at": "2024-01-15T10:30:05Z"9}
idstringtask id
statusnumberterminal status (9=completed, 10=failed, 11=cancelled)
outputobjecttask output (when completed)
errorstringerror message (when failed)
session_idstringsession id (if using sessions)
created_atstringiso timestamp
updated_atstringiso timestamp

5. schema

input

audioarray(stream)

microphone audio, a frame every 20 ms or so

eventsarray(stream)

typed messages: text from the user, or words for the assistant

instructionsstring

system prompt. grok's voice models take plain instructions; workarounds written for other models are unnecessary.

default: "You are a helpful assistant."
voicestring

a built-in voice; `voices` lists them with what xai says about each

default: "eve"
options:"eve""ara""rex""sal""leo""altair""atlas""aurora""carina""castor""celeste""cosmo""helios""helix""iris""kepler""liora""lumen""luna""lux""naksh""orion""perseus""rigel""sirius""ursa""zagan""zenith"
custom_voicestring

the id of a voice cloned with xai's custom voices api. set, it is used instead of voice.

modelstring

grok-voice-latest follows the newest model; pin a versioned name such as grok-voice-think-fast-2.0 for stability

default: "grok-voice-latest"
reasoningstring

whether the model thinks before it answers. 'none' answers faster.

default: "high"
options:"high""none"
languagestring

bcp-47 hint for what the user speaks, such as en, ja or es-mx (spanish and portuguese need a region). left empty it is detected.

speednumber

playback speed of the assistant's voice

default: 1min:0.7max:1.5
silence_msinteger

silence that ends the user's turn, in ms. left empty grok decides.

min:0max:10000
web_searchboolean

let the assistant search the web

default: false
x_searchboolean

let the assistant search x

default: false

output

assistant_textstring

what the assistant is saying, as it says it

audioarray(stream)

the assistant's voice

messagesarray

the conversation so far, a message per turn

partialboolean

true while the conversation goes on; false on the result

secondsnumber

how long the session has run

user_textstring

what grok hears the user saying, refined as they speak

ready to run grok-voice?

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.