> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magichour.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Voice Generator API Reference - Magic Hour Docs

> Generate speech from text. Each character costs 0.05 credits. The cost is rounded up to the nearest whole number.



## OpenAPI

````yaml post /v1/ai-voice-generator
openapi: 3.0.2
info:
  title: Magic Hour API
  version: beta
  description: >

    Magic Hour provides an API (beta) that can be integrated into your own
    application to generate videos and images using AI. 


    Webhook documentation can be found
    [here](https://magichour.ai/docs/webhook).


    If you have any questions, please reach out to us via
    [discord](https://discord.gg/JX5rgsZaJp).


    # Authentication


    Every request requires an API key.


    To get started, first generate your API key
    [here](https://magichour.ai/settings/developer).


    Then, add the `Authorization` header to the request.


    | Key | Value |

    |-|-|

    | Authorization | Bearer mhk_live_apikey |


    > **Warning**: any API call that renders a video will utilize credits in
    your account.
  termsOfService: https://magichour.ai/terms-of-service
servers:
  - url: https://api.magichour.ai
security: []
tags:
  - name: Files
    description: API related to uploading assets used for video generation
  - name: Image Projects
    description: API related to image projects
  - name: Video Projects
    description: API related to video projects
  - name: Audio Projects
    description: API related to audio projects
paths:
  /v1/ai-voice-generator:
    post:
      tags:
        - Audio Projects
      summary: AI Voice Generator
      description: >-
        Generate speech from text. Each character costs 0.05 credits. The cost
        is rounded up to the nearest whole number.
      operationId: aiVoiceGenerator.createAudio
      parameters: []
      requestBody:
        required: true
        description: Body
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Give your audio a custom name for easy identification.
                  example: My Voice Generator audio
                  default: Voice Generator - dateTime
                style:
                  type: object
                  properties:
                    prompt:
                      type: string
                      minLength: 1
                      description: >-
                        Text used to generate speech. The character limit is
                        1000 characters.
                      example: Hello, how are you?
                    voice_name:
                      type: string
                      enum:
                        - Elon Musk
                        - Mark Zuckerberg
                        - Joe Rogan
                        - Barack Obama
                        - Morgan Freeman
                        - Kanye West
                        - Donald Trump
                        - Joe Biden
                        - Kim Kardashian
                        - Taylor Swift
                        - James Earl Jones
                        - Samuel L. Jackson
                        - Jeff Goldblum
                        - David Attenborough
                        - Sean Connery
                        - Cillian Murphy
                        - Anne Hathaway
                        - Julia Roberts
                        - Natalie Portman
                        - Steve Carell
                        - Amy Poehler
                        - Stephen Colbert
                        - Jimmy Fallon
                        - David Letterman
                        - Alex Trebek
                        - Katy Perry
                        - Prince
                        - Kevin Bacon
                        - Tom Hiddleston
                        - Adam Driver
                        - Alan Rickman
                        - Alexz Johnson
                        - Ana Gasteyer
                        - Andrew Rannells
                        - Arden Cho
                        - Bear Grylls
                        - Ben McKenzie
                        - Ben Stiller
                        - Ben Whishaw
                        - Billie Joe Armstrong
                        - Bingbing Li
                        - Booboo Stewart
                        - Bradley Steven Perry
                        - Bruno Mars
                        - Caity Lotz
                        - Cameron Boyce
                        - Candice Accola
                        - Carrie Underwood
                        - Casey Affleck
                        - Caterina Scorsone
                        - Cedric the Entertainer
                        - Chace Crawford
                        - Chadwick Boseman
                        - Charlie Day
                        - Chris Hemsworth
                        - Chris Martin
                        - Christopher Mintz-Plasse
                        - Dan Fogler
                        - Dan Stevens
                        - Daniel Dae Kim
                        - Danielle Panabaker
                        - Dave Bautista
                        - David Schwimmer
                        - Denis Leary
                        - Derek Mears
                        - Diego Luna
                        - Donald Glover
                        - Donnie Yen
                        - Doutzen Kroes
                        - Dove Cameron
                        - Dr. Dre
                        - Drake Bell
                        - Elle Fanning
                        - Ernie Hudson
                        - Fergie
                        - Forest Whitaker
                        - Francia Raisa
                        - Freddie Highmore
                        - Gillian Jacobs
                        - Gina Carano
                        - Ginnifer Goodwin
                        - Gordon Ramsay
                        - Guy Pearce
                        - Gwendoline Christie
                        - Hailee Steinfeld
                        - Howie Mandel
                        - Hugh Jackman
                        - Hugh Laurie
                        - J. K. Simmons
                        - Jack Black
                        - Jared Leto
                        - Jennifer Carpenter
                        - Kesha
                        - Kris Jenner
                        - Kristen Bell
                        - Lorde
                        - Matt Smith
                        - Marilyn Monroe
                        - Charlie Chaplin
                        - Albert Einstein
                        - Abraham Lincoln
                        - John F. Kennedy
                        - Lucille Ball
                        - A.R. Rahman
                        - Aamir Khan
                        - Ajay Devgn
                        - Akshay Kumar
                        - Alain Delon
                        - Alan Alda
                        - Alan Cumming
                        - Amitabh Bachchan
                        - Ang Lee
                        - Ansel Elgort
                        - Anthony Anderson
                        - Anthony Mackie
                        - Armie Hammer
                        - Asa Butterfield
                        - B.J. Novak
                        - Barbara Eden
                        - Betty White
                        - Bill Nighy
                        - Bill Pullman
                        - Blake Shelton
                        - Bonnie Wright
                        - Brad Paisley
                        - Brendan Gleeson
                        - Brian Cox
                        - Bruno Ganz
                        - Burt Reynolds
                        - Carrie Fisher
                        - Charles Dance
                        - Chiwetel Ejiofor
                        - Chris Pine
                        - Christina Hendricks
                        - Christina Ricci
                        - Cyndi Lauper
                        - Dakota Fanning
                        - Damian Lewis
                        - Dan Aykroyd
                        - Daniel Craig
                        - David Oyelowo
                        - David Tennant
                        - Diane Keaton
                        - Diane Kruger
                        - Dick Van Dyke
                        - Domhnall Gleeson
                        - Dominic Cooper
                        - Donald Sutherland
                        - Drew Carey
                        - Eartha Kitt
                        - Eddie Izzard
                        - Edward Asner
                        - Eli Roth
                        - Elisabeth Moss
                        - Ellen Burstyn
                        - Emile Hirsch
                        - Ezra Miller
                        - Felicity Jones
                        - Fiona Shaw
                        - Florence Henderson
                        - Freida Pinto
                        - Geena Davis
                        - Gemma Arterton
                        - Geri Halliwell
                        - Glenn Close
                        - Gloria Steinem
                        - Greta Gerwig
                        - Gugu Mbatha-Raw
                        - Hans Zimmer
                        - Harry Connick Jr.
                        - Harvey Keitel
                        - Helena Bonham Carter
                        - Henry Cavill
                        - Hilary Swank
                        - Hugh Bonneville
                        - Idina Menzel
                        - Imelda Staunton
                        - Ingrid Bergman
                        - Irrfan Khan
                        - Isla Fisher
                        - Iwan Rheon
                        - Jack Lemmon
                        - Janet Jackson
                        - Jason Bateman
                        - Jason Segel
                        - Jennifer Coolidge
                        - Johnny Galecki
                        - Jon Favreau
                        - Joseph Gordon-Levitt
                        - Josh Brolin
                        - Josh Gad
                        - Josh Groban
                        - Julia Louis-Dreyfus
                        - Kristen Stewart
                        - Kristen Wiig
                        - Rooney Mara
                        - Caitriona Balfe
                        - J.J. Abrams
                        - Zoe Saldana
                      description: >-
                        The voice to use for the speech. Available voices: Elon
                        Musk, Mark Zuckerberg, Joe Rogan, Barack Obama, Morgan
                        Freeman, Kanye West, Donald Trump, Joe Biden, Kim
                        Kardashian, Taylor Swift, James Earl Jones, Samuel L.
                        Jackson, Jeff Goldblum, David Attenborough, Sean
                        Connery, Cillian Murphy, Anne Hathaway, Julia Roberts,
                        Natalie Portman, Steve Carell, Amy Poehler, Stephen
                        Colbert, Jimmy Fallon, David Letterman, Alex Trebek,
                        Katy Perry, Prince, Kevin Bacon, Tom Hiddleston, Adam
                        Driver, Alan Rickman, Alexz Johnson, Ana Gasteyer,
                        Andrew Rannells, Arden Cho, Bear Grylls, Ben McKenzie,
                        Ben Stiller, Ben Whishaw, Billie Joe Armstrong, Bingbing
                        Li, Booboo Stewart, Bradley Steven Perry, Bruno Mars,
                        Caity Lotz, Cameron Boyce, Candice Accola, Carrie
                        Underwood, Casey Affleck, Caterina Scorsone, Cedric the
                        Entertainer, Chace Crawford, Chadwick Boseman, Charlie
                        Day, Chris Hemsworth, Chris Martin, Christopher
                        Mintz-Plasse, Dan Fogler, Dan Stevens, Daniel Dae Kim,
                        Danielle Panabaker, Dave Bautista, David Schwimmer,
                        Denis Leary, Derek Mears, Diego Luna, Donald Glover,
                        Donnie Yen, Doutzen Kroes, Dove Cameron, Dr. Dre, Drake
                        Bell, Elle Fanning, Ernie Hudson, Fergie, Forest
                        Whitaker, Francia Raisa, Freddie Highmore, Gillian
                        Jacobs, Gina Carano, Ginnifer Goodwin, Gordon Ramsay,
                        Guy Pearce, Gwendoline Christie, Hailee Steinfeld, Howie
                        Mandel, Hugh Jackman, Hugh Laurie, J. K. Simmons, Jack
                        Black, Jared Leto, Jennifer Carpenter, Kesha, Kris
                        Jenner, Kristen Bell, Lorde, Matt Smith, Marilyn Monroe,
                        Charlie Chaplin, Albert Einstein, Abraham Lincoln, John
                        F. Kennedy, Lucille Ball, A.R. Rahman, Aamir Khan, Ajay
                        Devgn, Akshay Kumar, Alain Delon, Alan Alda, Alan
                        Cumming, Amitabh Bachchan, Ang Lee, Ansel Elgort,
                        Anthony Anderson, Anthony Mackie, Armie Hammer, Asa
                        Butterfield, B.J. Novak, Barbara Eden, Betty White, Bill
                        Nighy, Bill Pullman, Blake Shelton, Bonnie Wright, Brad
                        Paisley, Brendan Gleeson, Brian Cox, Bruno Ganz, Burt
                        Reynolds, Carrie Fisher, Charles Dance, Chiwetel
                        Ejiofor, Chris Pine, Christina Hendricks, Christina
                        Ricci, Cyndi Lauper, Dakota Fanning, Damian Lewis, Dan
                        Aykroyd, Daniel Craig, David Oyelowo, David Tennant,
                        Diane Keaton, Diane Kruger, Dick Van Dyke, Domhnall
                        Gleeson, Dominic Cooper, Donald Sutherland, Drew Carey,
                        Eartha Kitt, Eddie Izzard, Edward Asner, Eli Roth,
                        Elisabeth Moss, Ellen Burstyn, Emile Hirsch, Ezra
                        Miller, Felicity Jones, Fiona Shaw, Florence Henderson,
                        Freida Pinto, Geena Davis, Gemma Arterton, Geri
                        Halliwell, Glenn Close, Gloria Steinem, Greta Gerwig,
                        Gugu Mbatha-Raw, Hans Zimmer, Harry Connick Jr., Harvey
                        Keitel, Helena Bonham Carter, Henry Cavill, Hilary
                        Swank, Hugh Bonneville, Idina Menzel, Imelda Staunton,
                        Ingrid Bergman, Irrfan Khan, Isla Fisher, Iwan Rheon,
                        Jack Lemmon, Janet Jackson, Jason Bateman, Jason Segel,
                        Jennifer Coolidge, Johnny Galecki, Jon Favreau, Joseph
                        Gordon-Levitt, Josh Brolin, Josh Gad, Josh Groban, Julia
                        Louis-Dreyfus, Kristen Stewart, Kristen Wiig, Rooney
                        Mara, Caitriona Balfe, J.J. Abrams, Zoe Saldana
                      example: Elon Musk
                  required:
                    - prompt
                    - voice_name
                  description: The content used to generate speech.
                  example:
                    prompt: Hello, how are you?
                    voice_name: Elon Musk
              required:
                - style
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: cuid-example
                    description: >-
                      Unique ID of the audio. Use it with the [Get audio Project
                      API](https://docs.magichour.ai/api-reference/audio-projects/get-audio-details)
                      to fetch status and downloads.
                  credits_charged:
                    type: integer
                    description: >-
                      The amount of credits deducted from your account to
                      generate the audio. We charge credits right when the
                      request is made. 


                      If an error occurred while generating the audio, credits
                      will be refunded and this field will be updated to include
                      the refund.
                    example: 1
                required:
                  - id
                  - credits_charged
                description: Success
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
                description: The request is invalid
                example:
                  message: Missing request body
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Unauthorized
                required:
                  - message
                description: The request is not properly authenticated
                example:
                  message: Unauthorized
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
                description: The request requires payment
                example:
                  message: Payment required
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Not Found
                required:
                  - message
                description: Requested resource is not found
                example:
                  message: Not Found
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Unable to generate speech
                required:
                  - message
                description: Unprocessable Entity
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: python
          source: |-
            from magic_hour import Client
            from os import getenv

            client = Client(token=getenv("API_TOKEN"))
            res = client.v1.ai_voice_generator.generate(
                style={"prompt": "Hello, how are you?", "voice_name": "Elon Musk"},
                name="Voice Generator audio",
                wait_for_completion=True,
                download_outputs=True,
                download_directory="."
            )
        - lang: javascript
          source: |-
            import { Client } from "magic-hour";

            const client = new Client({ token: process.env["API_TOKEN"]!! });
            const res = await client.v1.aiVoiceGenerator.generate(
              {
                name: "Voice Generator audio",
                style: { prompt: "Hello, how are you?", voiceName: "Elon Musk" },
              },
              {
                waitForCompletion: true,
                downloadOutputs: true,
                downloadDirectory: ".",
              },
            );
        - lang: go
          source: "package main\n\nimport (\n\tos \"os\"\n\n\tsdk \"github.com/magichourhq/magic-hour-go/client\"\n\tnullable \"github.com/magichourhq/magic-hour-go/nullable\"\n\tai_voice_generator \"github.com/magichourhq/magic-hour-go/resources/v1/ai_voice_generator\"\n\ttypes \"github.com/magichourhq/magic-hour-go/types\"\n)\n\nfunc main() {\n\tclient := sdk.NewClient(\n\t\tsdk.WithBearerAuth(os.Getenv(\"API_TOKEN\")),\n\t)\n\tres, err := client.V1.AiVoiceGenerator.Create(ai_voice_generator.CreateRequest{\n\t\tName: nullable.NewValue(\"My Voice Generator audio\"),\n\t\tStyle: types.V1AiVoiceGeneratorCreateBodyStyle{\n\t\t\tPrompt:    \"Hello, how are you?\",\n\t\t\tVoiceName: types.V1AiVoiceGeneratorCreateBodyStyleVoiceNameEnumElonMusk,\n\t\t},\n\t})\n}"
        - lang: rust
          source: |-
            let client = magic_hour::Client::default()
                .with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
            let res = client
                .v1()
                .ai_voice_generator()
                .create(magic_hour::resources::v1::ai_voice_generator::CreateRequest {
                    name: Some("My Voice Generator audio".to_string()),
                    style: magic_hour::models::V1AiVoiceGeneratorCreateBodyStyle {
                        prompt: "Hello, how are you?".to_string(),
                        voice_name: magic_hour::models::V1AiVoiceGeneratorCreateBodyStyleVoiceNameEnum::ElonMusk,
                    },
                })
                .await;
        - lang: curl
          source: |-
            curl --request POST \
                 --url https://api.magichour.ai/v1/ai-voice-generator \
                 --header 'accept: application/json' \
                 --header 'authorization: Bearer <token>' \
                 --header 'content-type: application/json' \
                 --data '
            {
              "name": "My Voice Generator audio",
              "style": {
                "prompt": "Hello, how are you?",
                "voice_name": "Elon Musk"
              }
            }
            '
        - lang: php
          source: |-
            <?php

            $curl = curl_init();

            curl_setopt_array($curl, [
              CURLOPT_URL => "https://api.magichour.ai/v1/ai-voice-generator",
              CURLOPT_RETURNTRANSFER => true,
              CURLOPT_ENCODING => "",
              CURLOPT_MAXREDIRS => 10,
              CURLOPT_TIMEOUT => 30,
              CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
              CURLOPT_CUSTOMREQUEST => "POST",
              CURLOPT_POSTFIELDS => json_encode([
                'name' => 'My Voice Generator audio',
                'style' => [
                    'prompt' => 'Hello, how are you?',
                    'voice_name' => 'Elon Musk'
                ]
              ]),
              CURLOPT_HTTPHEADER => [
                "accept: application/json",
                "authorization: Bearer <token>",
                "content-type: application/json"
              ],
            ]);

            $response = curl_exec($curl);
            $err = curl_error($curl);

            curl_close($curl);

            if ($err) {
              echo "cURL Error #:" . $err;
            } else {
              echo $response;
            }
        - lang: java
          source: >-
            HttpResponse<String> response =
            Unirest.post("https://api.magichour.ai/v1/ai-voice-generator")
              .header("accept", "application/json")
              .header("content-type", "application/json")
              .header("authorization", "Bearer <token>")
              .body("{\"name\":\"My Voice Generator audio\",\"style\":{\"prompt\":\"Hello, how are you?\",\"voice_name\":\"Elon Musk\"}}")
              .asString();
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <api_key>`, where
        `<api_key>` is your API key. To get your API key, go to [Developer
        Hub](https://magichour.ai/developer?tab=api-keys) and click "Create new
        API Key".

````