Rerank - Go SDK

Rerank method reference

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

Overview

Reranking endpoints

Available Operations

  • Rerank - Submit a rerank request

Rerank

Submits a rerank request to the rerank 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.Rerank.Rerank(ctx, operations.CreateRerankRequest{
19 Model: "cohere/rerank-v3.5",
20 Query: "What is the capital of France?",
21 Documents: []string{
22 "Paris is the capital of France.",
23 "Berlin is the capital of Germany.",
24 "Madrid is the capital of Spain.",
25 },
26 })
27 if err != nil {
28 log.Fatal(err)
29 }
30 if res != nil {
31 // handle response
32 }
33}

Parameters

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

Response

*operations.CreateRerankResponse, 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*/*