Create client secret
ClientSecretCreateResponse realtime().clientSecrets().create(ClientSecretCreateParamsparams = ClientSecretCreateParams.none(), RequestOptionsrequestOptions = RequestOptions.none())
POST/realtime/client_secrets
Create a Realtime client secret with an associated session configuration.
Client secrets are short-lived tokens that can be passed to a client app, such as a web frontend or mobile client, which grants access to the Realtime API without leaking your main API key. You can configure a custom TTL for each client secret.
You can also attach session configuration options to the client secret, which will be applied to any sessions created using that client secret, but these can also be overridden by the client connection.
Learn more about authentication with client secrets over WebRTC.
Returns the created client secret and the effective session object. The client secret is a string that looks like ek_1234.
Create client secret
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.realtime.clientsecrets.ClientSecretCreateParams;
import com.openai.models.realtime.clientsecrets.ClientSecretCreateResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
ClientSecretCreateResponse clientSecret = client.realtime().clientSecrets().create();
}
}{
"value": "ek_68af296e8e408191a1120ab6383263c2",
"expires_at": 1756310470,
"session": {
"type": "realtime",
"object": "realtime.session",
"id": "sess_C9CiUVUzUzYIssh3ELY1d",
"model": "gpt-realtime",
"output_modalities": [
"audio"
],
"instructions": "You are a friendly assistant.",
"tools": [],
"tool_choice": "auto",
"max_output_tokens": "inf",
"tracing": null,
"truncation": "auto",
"prompt": null,
"expires_at": 0,
"audio": {
"input": {
"format": {
"type": "audio/pcm",
"rate": 24000
},
"transcription": null,
"noise_reduction": null,
"turn_detection": {
"type": "server_vad",
}
},
"output": {
"format": {
"type": "audio/pcm",
"rate": 24000
},
"voice": "alloy",
"speed": 1.0
}
},
"include": null
}
}
Returns Examples
{
"value": "ek_68af296e8e408191a1120ab6383263c2",
"expires_at": 1756310470,
"session": {
"type": "realtime",
"object": "realtime.session",
"id": "sess_C9CiUVUzUzYIssh3ELY1d",
"model": "gpt-realtime",
"output_modalities": [
"audio"
],
"instructions": "You are a friendly assistant.",
"tools": [],
"tool_choice": "auto",
"max_output_tokens": "inf",
"tracing": null,
"truncation": "auto",
"prompt": null,
"expires_at": 0,
"audio": {
"input": {
"format": {
"type": "audio/pcm",
"rate": 24000
},
"transcription": null,
"noise_reduction": null,
"turn_detection": {
"type": "server_vad",
}
},
"output": {
"format": {
"type": "audio/pcm",
"rate": 24000
},
"voice": "alloy",
"speed": 1.0
}
},
"include": null
}
}