Install
openclaw skills install @psyb0t/go-elevenlabsUnofficial Go client for the ElevenLabs REST API, generated with oapi-codegen. elevenlabs.NewClientWithResponses("https://api.elevenlabs.io", opts...) from github.com/psyb0t/go-elevenlabs returns a *elevenlabs.ClientWithResponses with one typed <Operation>WithResponse method per endpoint (voices, text to speech, speech to text, sound effects, dubbing, user info and more). Auth is the xi-api-key header set through elevenlabs.WithRequestEditorFn; JSON replies decode into JSON200, and audio replies come back as raw bytes in Body. Use when Go code needs to call ElevenLabs or already imports go-elevenlabs.
openclaw skills install @psyb0t/go-elevenlabsTyped Go client for the ElevenLabs API. Every endpoint in the ElevenLabs OpenAPI document is a method on ClientWithResponses.
For install, client options, more operations and response handling, see references/setup.md.
ELEVENLABS_API_KEY. Never hardcode it, commit it or log it, and never print request headers.https://api.elevenlabs.io. Text, audio and voice samples you send are processed by ElevenLabs.github.com/psyb0t/go-elevenlabs.import (
"context"
"fmt"
"net/http"
"os"
"github.com/psyb0t/go-elevenlabs"
)
auth := elevenlabs.WithRequestEditorFn(
func(_ context.Context, req *http.Request) error {
req.Header.Set("xi-api-key", os.Getenv("ELEVENLABS_API_KEY"))
return nil
},
)
client, err := elevenlabs.NewClientWithResponses(
"https://api.elevenlabs.io",
auth,
)
if err != nil {
return err
}
voices, err := client.GetVoicesWithResponse(ctx, nil)
if err != nil {
return err // transport failure
}
if voices.JSON200 == nil {
return fmt.Errorf("elevenlabs: status %d", voices.StatusCode())
}
for _, voice := range voices.JSON200.Voices {
fmt.Println(voice.VoiceId, voice.Name)
}
Text to speech. A 200 reply is audio, so read Body:
speech, err := client.TextToSpeechFullWithResponse(
ctx,
voiceID,
nil,
elevenlabs.TextToSpeechFullJSONRequestBody{Text: "Hello there."},
)
if err != nil {
return err
}
if speech.StatusCode() != http.StatusOK {
return fmt.Errorf("elevenlabs: status %d", speech.StatusCode())
}
audio := speech.Body // encoded per params.OutputFormat, e.g. mp3_44100_128
Leave the XiApiKey field of every ...Params struct nil and let the request editor set the header.
A method returns an error only when the request could not be sent or the body could not be decoded. An API error is a normal response: check StatusCode(); a 422 also fills JSON422, an *HTTPValidationError.