Share via

Python code to generate ephemeral token for gpt-4o-mini-transcribe OR gpt-4o-transcribe

GenixPRO 176 Reputation points
2026-02-25T12:42:59.1733333+00:00

Hi Team,

  1. We're unable to find ways/python code to generate ephemeral token for gpt-4o-mini-transcribe OR gpt-4o-transcribe. Searched online & there are some references for generating such tokens for realtime API. But none for gpt-4o-mini-transcribe. Can you pls. share any reference/quickstart guide for this.
  2. Is gpt-4o-mini-transcribe run within realtime API? For speech-to-text use-case, we notice a significant price difference between gpt-4o-mini-transcribe & realtime API in transcription mode. As such, we don't wish to use realtime API for this case. Can ephemeral token be generated for gpt-4o-mini-transcribe?

Thanks in advance for the help.

Azure AI Speech
Azure AI Speech

An Azure service that integrates speech processing into apps and services.

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anshika Varshney 7,995 Reputation points Microsoft External Staff Moderator
    2026-03-02T16:47:22.3466667+00:00

    Hi GenixPRO,

    Thanks for raising this question. Currently, ephemeral tokens are supported only via the Realtime API flow. Models such as gpt‑4o‑mini‑transcribe and gpt‑4o‑transcribe can generate ephemeral tokens only when used in a realtime session, not for standard (non‑realtime) transcription requests.

    If your use case is batch or request‑response speech‑to‑text, ephemeral token generation isn’t available outside the Realtime API today. This is why you’re seeing references only for realtime scenarios and not for standalone transcription endpoints.

    Given the pricing and architecture differences you mentioned, the recommended approach for non‑realtime transcription remains using the regular Speech / transcription APIs with standard authentication. If ephemeral tokens are required for non‑realtime transcription in the future, that would need to be a platform enhancement.

    Please let me know if there are any remaining questions or additional details, I can help with, I’ll be glad to provide further clarification or guidance.

    If this answers your query, please do click Accept Answer and Yes for was this answer helpful.

    Thankyou!

    0 comments No comments

  2. Q&A Assist
    2026-02-25T12:43:12.29+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To generate an ephemeral token for the gpt-4o-mini-transcribe or gpt-4o-transcribe models, you can use the REST API provided by Azure. Here’s a brief overview of the steps involved:

    1. Set up the service to procure the ephemeral token: You will need to make a request to the following URL to generate the ephemeral token:
         https://{your azure resource}.openai.azure.com/openai/v1/realtime/client_secrets
      
      This request can be authenticated using either an API key or a Microsoft Entra ID token.
    2. Session Configuration: In your request, you will need to specify the session configuration, which includes:
      • session.type: Must be set to realtime.
      • session.model: Specify your model deployment name (either gpt-4o-mini-transcribe or gpt-4o-transcribe).
      • Optional fields like session.instructions and session.audio.output.voice can also be included.
    3. Sample Python Code: Here’s a basic example of how you might implement this in Python:
         import requests
         from azure.identity import DefaultAzureCredential
         
         # Replace with your Azure resource name
         azure_resource = "<your azure resource>"
         url = f"https://{azure_resource}.openai.azure.com/openai/v1/realtime/client_secrets"
         
         # Authenticate and get the token
         credential = DefaultAzureCredential()
         token = credential.get_token("https://openai.azure.com/.default")
         
         headers = {
             "Authorization": f"Bearer {token.token}",
             "Content-Type": "application/json"
         }
         
         # Session configuration
         data = {
             "session": {
                 "type": "realtime",
                 "model": "gpt-4o-mini-transcribe"
             }
         }
         
         response = requests.post(url, headers=headers, json=data)
         ephemeral_token = response.json()
         print(ephemeral_token)
      

    Make sure to replace the placeholder values with your actual Azure resource details and model deployment names. This code will help you generate an ephemeral token for the specified models.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.