Can one get embeddings from an inference API that computes Sentence Similarity (in 2023)?

I’m trying to get embedding from a sentence similarity endpoint directly.

I found some old threads providing solutions that don’t seem to work, like this one

Locally I can get the effect I want calling model.encode via sentence-transformers and grabbing ‘embeddings’ from the output.

Is it possible to use HF API for that?

For me, this code works:

API_URL = “https://huggingface.co/proxy/router.huggingface.co/hf-inference/models/sentence-transformers/LaBSE/pipeline/feature-extraction”
headers = {
“Authorization”: “Bearer HF_TOKEN”,
}

def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()

output = query({
“inputs”: {
“sentences”: [
“That is a happy dog”,
“That is a very happy person”,
“Today is a sunny da”
]
},
})

print(output)

So from the example code given on the model page “view code snippets”, just changing /pipeline/sentence-similarity for /pipeline/feature-extraction and removing the source_sentence from the query, results in an output of embeddings for me.