curl --request POST \
--url https://api.langdock.com/openai/{region}/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog",
"encoding_format": "float"
}
'import requests
url = "https://api.langdock.com/openai/{region}/v1/embeddings"
payload = {
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog",
"encoding_format": "float"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'text-embedding-ada-002',
input: 'The quick brown fox jumps over the lazy dog',
encoding_format: 'float'
})
};
fetch('https://api.langdock.com/openai/{region}/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/openai/{region}/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'text-embedding-ada-002',
'input' => 'The quick brown fox jumps over the lazy dog',
'encoding_format' => 'float'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/openai/{region}/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/openai/{region}/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/openai/{region}/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"embedding": [
0.0023064255,
-0.009327292,
"..."
],
"index": 0,
"object": "embedding"
}
],
"model": "text-embedding-ada-002",
"object": "list",
"usage": {
"prompt_tokens": 9,
"total_tokens": 9
}
}{
"message": "No embedding models available for the ${region} region"
}{
"message": "The provided API key is invalid."
}{
"message": "Rate limit for public API exceeded"
}{
"message": "Internal Server Error"
}OpenAI Embeddings
Erstellt Embeddings für Text mit OpenAIs Embedding-Modellen
curl --request POST \
--url https://api.langdock.com/openai/{region}/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog",
"encoding_format": "float"
}
'import requests
url = "https://api.langdock.com/openai/{region}/v1/embeddings"
payload = {
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog",
"encoding_format": "float"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'text-embedding-ada-002',
input: 'The quick brown fox jumps over the lazy dog',
encoding_format: 'float'
})
};
fetch('https://api.langdock.com/openai/{region}/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/openai/{region}/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'text-embedding-ada-002',
'input' => 'The quick brown fox jumps over the lazy dog',
'encoding_format' => 'float'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/openai/{region}/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/openai/{region}/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/openai/{region}/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"text-embedding-ada-002\",\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"encoding_format\": \"float\"\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"embedding": [
0.0023064255,
-0.009327292,
"..."
],
"index": 0,
"object": "embedding"
}
],
"model": "text-embedding-ada-002",
"object": "list",
"usage": {
"prompt_tokens": 9,
"total_tokens": 9
}
}{
"message": "No embedding models available for the ${region} region"
}{
"message": "The provided API key is invalid."
}{
"message": "Rate limit for public API exceeded"
}{
"message": "Internal Server Error"
}Bevor du startest
- API-Key: Um die API zu nutzen, fragst du deinen Workspace-Admin nach einem Workspace-API-Key mit dem Scope Embedding API. Persönliche API-Keys enthalten ausschließlich den Scope Completion API und können diesen Endpunkt nicht aufrufen.
Basis-URL
https://api.langdock.com/openai/{region}/v1/embeddings
api.langdock.com durch <your-deployment-url>/api/public in allen Anfragen.Parameter
Alle Parameter vom OpenAI Embeddings endpoint werden gemäß den OpenAI-Spezifikationen unterstützt, mit folgenden Ausnahmen:model: Derzeit wird nur dastext-embedding-ada-002Modell unterstützt.encoding_format: Unterstützt sowohlfloatals auchbase64Formate.
Rate Limits
Die Standard-Limits sind 500 RPM (Anfragen pro Minute) und 150.000 TPM (Tokens pro Minute).- RPM wird je Workspace, Modell und API-Key begrenzt.
- TPM teilen sich alle API-Keys, die dasselbe Modell in einem Workspace verwenden.
- In Dedicated Deployments können Admins unter Einstellungen > Workspace > Produkte > API eigene Limits je Modell festlegen.
429 Too Many Requests Antwort.
Verwendung von OpenAI-kompatiblen Bibliotheken
Da das Anfrage- und Antwortformat dasselbe wie bei der OpenAI API ist, kannst du beliebte Bibliotheken wie die OpenAI Python library oder das Vercel AI SDK verwenden, um die Langdock API zu nutzen.Beispiel mit der OpenAI Python-Bibliothek
from openai import OpenAI
client = OpenAI(
base_url="https://api.langdock.com/openai/eu/v1",
api_key="<YOUR_LANGDOCK_API_KEY>"
)
embedding = client.embeddings.create(
model="text-embedding-ada-002",
input="The quick brown fox jumps over the lazy dog",
encoding_format="float"
)
print(embedding.data[0].embedding)
Beispiel mit dem Vercel AI SDK in Node.js
import { createOpenAI } from "@ai-sdk/openai";
const langdockProvider = createOpenAI({
baseURL: "https://api.langdock.com/openai/eu/v1",
apiKey: "<YOUR_LANGDOCK_API_KEY>",
});
const response = await langdockProvider.embeddings.create({
model: "text-embedding-ada-002",
input: "The quick brown fox jumps over the lazy dog",
encoding_format: "float",
});
console.log(response.data[0].embedding);
Autorisierungen
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Pfadparameter
The region of the API to use.
eu, us Body
Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs in a single request, pass an array of strings or array of tokens, e.g. ["text1", "text2"]. Each input must not exceed 8192 tokens in length.
ID of the model to use. You can use the List models API to see all of your available models, or see OpenAI's Model overview for descriptions of them.
The format to return the embeddings in. Can be either float or base64.
float, base64 The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
x >= 1A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
Antwort
OK
The list of embeddings generated by the model.
Show child attributes
Show child attributes
The name of the model used to generate the embedding.
The object type, which is always "list".
list Show child attributes
Show child attributes
War diese Seite hilfreich?