Documentation
¶
Overview ¶
Package elevenlabs provides a small Go client for the ElevenLabs API.
Index ¶
- func DecodeOptionalResponse(body []byte) (any, error)
- func DecodeResponse(body []byte, out any) error
- type APIError
- type Client
- func (c *Client) AuthHeader() (http.Header, error)
- func (c *Client) Do(ctx context.Context, build RequestBuilder, retryable bool) ([]byte, RawResponse, error)
- func (c *Client) Endpoint(path string) (string, error)
- func (c *Client) GetJSON(ctx context.Context, path string, out any) (RawResponse, error)
- func (c *Client) GetUser(ctx context.Context) (*User, error)
- func (c *Client) GetUserWithResponse(ctx context.Context) (*Response[*User], error)
- func (c *Client) ListModels(ctx context.Context) ([]Model, error)
- func (c *Client) ListModelsWithResponse(ctx context.Context) (*Response[[]Model], error)
- func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)
- type ClientOption
- type Model
- type ModelLanguage
- type ModelRates
- type RawResponse
- type RequestBuilder
- type Response
- type RetryConfig
- type User
- type UserInvoice
- type UserSubscription
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeOptionalResponse ¶ added in v0.2.0
DecodeOptionalResponse decodes a JSON response body when one is present.
func DecodeResponse ¶ added in v0.2.0
DecodeResponse decodes a JSON response body into out.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Status string
Message string
Body []byte
ProviderType string
ProviderCode string
ProviderStatus string
ProviderMessage string
RequestID string
TraceID string
RetryAfter string
Validation []ValidationError
RawResponse RawResponse
}
APIError is returned when the ElevenLabs API responds with a non-2xx status.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an ElevenLabs API client.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a Client that authenticates with apiKey.
func (*Client) AuthHeader ¶ added in v0.2.0
AuthHeader returns the API key auth header for non-standard transports.
func (*Client) Do ¶ added in v0.2.0
func (c *Client) Do(ctx context.Context, build RequestBuilder, retryable bool) ([]byte, RawResponse, error)
Do executes requests with the client's retry policy.
func (*Client) Endpoint ¶ added in v0.2.0
Endpoint resolves an API path against the configured base URL.
func (*Client) GetJSON ¶ added in v0.2.0
GetJSON sends a retryable GET request and decodes the JSON response.
func (*Client) GetUserWithResponse ¶
GetUserWithResponse gets information about the authenticated user and returns HTTP response metadata.
func (*Client) ListModels ¶
ListModels gets the list of available models.
func (*Client) ListModelsWithResponse ¶
ListModelsWithResponse gets the list of available models and returns HTTP response metadata.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL overrides the ElevenLabs API base URL.
This is primarily useful for tests.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient overrides the HTTP client used for requests.
func WithRetryConfig ¶
func WithRetryConfig(cfg RetryConfig) ClientOption
WithRetryConfig overrides the retry policy used for replayable requests.
type Model ¶
type Model struct {
ModelID string `json:"model_id"`
Name string `json:"name,omitempty"`
CanBeFinetuned bool `json:"can_be_finetuned,omitempty"`
CanDoTextToSpeech bool `json:"can_do_text_to_speech,omitempty"`
CanDoVoiceConversion bool `json:"can_do_voice_conversion,omitempty"`
CanUseStyle bool `json:"can_use_style,omitempty"`
CanUseSpeakerBoost bool `json:"can_use_speaker_boost,omitempty"`
ServesProVoices bool `json:"serves_pro_voices,omitempty"`
TokenCostFactor float64 `json:"token_cost_factor,omitempty"`
Description string `json:"description,omitempty"`
RequiresAlphaAccess bool `json:"requires_alpha_access,omitempty"`
MaxCharactersRequestFreeUser int `json:"max_characters_request_free_user,omitempty"`
MaxCharactersRequestSubscribedUser int `json:"max_characters_request_subscribed_user,omitempty"`
MaximumTextLengthPerRequest int `json:"maximum_text_length_per_request,omitempty"`
Languages []ModelLanguage `json:"languages,omitempty"`
ModelRates *ModelRates `json:"model_rates,omitempty"`
ConcurrencyGroup string `json:"concurrency_group,omitempty"`
}
Model contains metadata for an ElevenLabs model.
type ModelLanguage ¶
ModelLanguage contains language metadata supported by a model.
type ModelRates ¶
type ModelRates struct {
CharacterCostMultiplier float64 `json:"character_cost_multiplier"`
CostDiscountMultiplier float64 `json:"cost_discount_multiplier,omitempty"`
}
ModelRates contains billing rate metadata for a model.
type RawResponse ¶
RawResponse contains HTTP response metadata.
It intentionally does not include the response body.
type RequestBuilder ¶ added in v0.2.0
RequestBuilder builds an HTTP request for one attempt.
type Response ¶
type Response[T any] struct { Data T RawResponse RawResponse }
Response contains parsed API data and HTTP response metadata.
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
BaseDelay time.Duration
MaxDelay time.Duration
StatusCodes []int
}
RetryConfig configures automatic retries for replayable requests.
MaxAttempts is the total number of attempts, including the initial request. Values less than or equal to 1 disable retries.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns the default retry policy.
type User ¶
type User struct {
UserID string `json:"user_id,omitempty"`
Subscription *UserSubscription `json:"subscription,omitempty"`
IsNewUser bool `json:"is_new_user,omitempty"`
XIAPIKey string `json:"xi_api_key,omitempty"`
CanUseDelayedPaymentMethods bool `json:"can_use_delayed_payment_methods,omitempty"`
IsOnboardingCompleted bool `json:"is_onboarding_completed,omitempty"`
FirstName string `json:"first_name,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
SeatType string `json:"seat_type,omitempty"`
IsAPIKeyHashed bool `json:"is_api_key_hashed,omitempty"`
XIAPIKeyPreview string `json:"xi_api_key_preview,omitempty"`
ShowComplianceTerms bool `json:"show_compliance_terms,omitempty"`
AvailableModels []string `json:"available_models,omitempty"`
NextInvoice *UserInvoice `json:"next_invoice,omitempty"`
}
User contains account metadata returned by the ElevenLabs user endpoint.
type UserInvoice ¶
type UserInvoice struct {
AmountDueCents int64 `json:"amount_due_cents,omitempty"`
NextPaymentAttemptUnix int64 `json:"next_payment_attempt_unix,omitempty"`
}
UserInvoice contains upcoming invoice metadata.
type UserSubscription ¶
type UserSubscription struct {
Tier string `json:"tier,omitempty"`
CharacterCount int64 `json:"character_count,omitempty"`
CharacterLimit int64 `json:"character_limit,omitempty"`
CanExtendCharacterLimit bool `json:"can_extend_character_limit,omitempty"`
AllowedToExtendCharacterLimit bool `json:"allowed_to_extend_character_limit,omitempty"`
NextCharacterCountResetUnix int64 `json:"next_character_count_reset_unix,omitempty"`
VoiceLimit int64 `json:"voice_limit,omitempty"`
MaxVoiceAddEdits int64 `json:"max_voice_add_edits,omitempty"`
VoiceAddEditCounter int64 `json:"voice_add_edit_counter,omitempty"`
ProfessionalVoiceLimit int64 `json:"professional_voice_limit,omitempty"`
CanExtendVoiceLimit bool `json:"can_extend_voice_limit,omitempty"`
CanUseInstantVoiceCloning bool `json:"can_use_instant_voice_cloning,omitempty"`
CanUseProfessionalVoiceCloning bool `json:"can_use_professional_voice_cloning,omitempty"`
Currency string `json:"currency,omitempty"`
Status string `json:"status,omitempty"`
BillingPeriod string `json:"billing_period,omitempty"`
CharacterRefreshPeriod string `json:"character_refresh_period,omitempty"`
NextInvoice *UserInvoice `json:"next_invoice,omitempty"`
HasOpenInvoices bool `json:"has_open_invoices,omitempty"`
CanUsePVCInstantly bool `json:"can_use_pvc_instantly,omitempty"`
CanUseVoiceDesign bool `json:"can_use_voice_design,omitempty"`
CanUseInstantVoiceCloningTrial bool `json:"can_use_instant_voice_cloning_trial,omitempty"`
CanUseProfessionalVoiceCloningTrial bool `json:"can_use_professional_voice_cloning_trial,omitempty"`
}
UserSubscription contains subscription and quota metadata for a user.
type ValidationError ¶
type ValidationError struct {
Loc []any `json:"loc"`
Msg string `json:"msg"`
Type string `json:"type"`
}
ValidationError contains validation details returned by the ElevenLabs API.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package speechtotext provides ElevenLabs speech-to-text APIs.
|
Package speechtotext provides ElevenLabs speech-to-text APIs. |