Embeddings - Go SDK

Embeddings method reference

The Go SDK and docs are currently in beta. Report issues on GitHub.

Overview

Text embedding endpoints

Available Operations

Generate

Submits an embedding request to the embeddings router

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/models/operations"
8 "log"
9)
10
11func main() {
12 ctx := context.Background()
13
14 s := openrouter.New(
15 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
16 )
17
18 res, err := s.Embeddings.Generate(ctx, operations.CreateEmbeddingsRequest{
19 Input: operations.CreateInputUnionStr(
20 "The quick brown fox jumps over the lazy dog",
21 ),
22 Model: "openai/text-embedding-3-small",
23 })
24 if err != nil {
25 log.Fatal(err)
26 }
27 if res != nil {
28 // handle response
29 }
30}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
requestoperations.CreateEmbeddingsRequest✔️The request object to use for the request.
opts[]operations.OptionThe options for this request.

Response

*operations.CreateEmbeddingsResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.PaymentRequiredResponseError402application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.BadGatewayResponseError502application/json
sdkerrors.ServiceUnavailableResponseError503application/json
sdkerrors.EdgeNetworkTimeoutResponseError524application/json
sdkerrors.ProviderOverloadedResponseError529application/json
sdkerrors.APIError4XX, 5XX*/*

ListModels

Returns a list of all available embeddings models and their properties

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "log"
8)
9
10func main() {
11 ctx := context.Background()
12
13 s := openrouter.New(
14 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
15 )
16
17 res, err := s.Embeddings.ListModels(ctx)
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
opts[]operations.OptionThe options for this request.

Response

*components.ModelsListResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*