Skip to content

feat: add embeddings API support#38

Merged
reVrost merged 2 commits intoreVrost:mainfrom
nitschmann:feat/embeddings-api-support
Nov 30, 2025
Merged

feat: add embeddings API support#38
reVrost merged 2 commits intoreVrost:mainfrom
nitschmann:feat/embeddings-api-support

Conversation

@nitschmann
Copy link
Contributor

Adds first-class support for the OpenRouter embeddings API to go-openrouter, plus a small example under examples/embeddings.

This implements the feature requested in #37 and follows the official embeddings API spec from OpenRouter.AI docs: https://openrouter.ai/docs/api/reference/embeddings

Copy link
Owner

@reVrost reVrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nitschmann , just a few small comments

embeddings.go Outdated
) (response EmbeddingsResponse, err error) {
if !isSupportingModel(embeddingsSuffix, request.Model) {
// Keep behavior consistent with chat/completions: let the server return a
// proper API error until we implement local model validation.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we potentially missing a return err here? otherwise we could remove this if block if it is not currently implemented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this for now, the API always return an proper error if anyhow an invalid model is being used :)

embeddings.go Outdated
withBody(request),
)
if err != nil {
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better if we could be explicit with our returns here and return an empty embedding response and err here
e.g
return EmbeddingResponse{}, err

Similarly on line 123/124, preferably avoid Named Return Values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Let me adjust this.

@nitschmann
Copy link
Contributor Author

Made some changes @reVrost and ensuring now that GET v1/embeddings/models API endpoint is supported as well.

Copy link
Owner

@reVrost reVrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you nice work @nitschmann! 🎉

@reVrost reVrost merged commit 0988189 into reVrost:main Nov 30, 2025
1 check passed
@nitschmann nitschmann deleted the feat/embeddings-api-support branch November 30, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants