> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langdock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Embeddings

> Erstellt Embeddings für Text mit OpenAIs Embedding-Modellen

<Info>
  **⚠️ Du nutzt unsere API in einem Dedicated Deployment?** Ersetze einfach `api.langdock.com` durch die Base URL deines Deployments: **`<deployment-url>/api/public`**
</Info>

Erstellt Embeddings für Text mit OpenAIs Embedding-Modellen. Dieser Endpunkt folgt der [OpenAI API specification](https://platform.openai.com/docs/api-reference/embeddings) und die Anfragen werden an den Azure OpenAI-Endpunkt gesendet.

<Info>
  Um die API zu nutzen, benötigst du einen API-Schlüssel. Administratoren können API-Schlüssel in den Einstellungen erstellen.
</Info>

Alle Parameter vom [OpenAI Embeddings endpoint](https://platform.openai.com/docs/api-reference/embeddings) werden gemäß den OpenAI-Spezifikationen unterstützt, mit folgenden Ausnahmen:

* `model`: Derzeit wird nur das `text-embedding-ada-002` Modell unterstützt.
* `encoding_format`: Unterstützt sowohl `float` als auch `base64` Formate.

## Rate Limits

Die Rate Limit für den Embeddings-Endpunkt beträgt **500 RPM (Anfragen pro Minute)** und **60,000 TPM (Token pro Minute)**. Rate Limits werden auf Workspace-Ebene definiert - und nicht auf API-Schlüssel-Ebene. Wenn du deine Rate Limit überschreitest, erhältst du eine `429 Too Many Requests` Antwort.

Bitte beachte, dass die Rate Limits Änderungen unterliegen. Beziehe dich auf diese Dokumentation für die aktuellsten Informationen.
Falls du eine höhere Rate Limit benötigst, kontaktiere uns bitte unter [support@langdock.com](mailto:support@langdock.com).

## 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](https://github.com/openai/openai-python) oder das [Vercel AI SDK](https://ai-sdk.dev/docs/introduction) verwenden, um die Langdock API zu nutzen.

### Beispiel mit der OpenAI Python-Bibliothek

```python theme={null}
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

```typescript theme={null}
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);
```

<Info>
  Langdock blockiert bewusst Browser-basierte Anfragen, um deinen API-Schlüssel zu schützen und die Sicherheit deiner Anwendungen zu gewährleisten. Weitere Informationen findest du in unserem Guide zu [Best Practices für API-Schlüssel](/de/admin/ai-adoption-and-rollout/best-practices/api-key-best-practices).
</Info>


## OpenAPI

````yaml POST /openai/{region}/v1/embeddings
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
    description: Production
security:
  - bearerAuth: []
paths:
  /openai/{region}/v1/embeddings:
    post:
      tags:
        - Embeddings
      summary: Creates embeddings for the given input text.
      parameters:
        - name: region
          in: path
          required: true
          description: The region of the API to use.
          schema:
            type: string
            enum:
              - eu
              - us
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateEmbeddingRequest'
            example:
              model: text-embedding-ada-002
              input: The quick brown fox jumps over the lazy dog
              encoding_format: float
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateEmbeddingResponse'
              example:
                data:
                  - embedding:
                      - 0.0023064255
                      - -0.009327292
                      - ...
                    index: 0
                    object: embedding
                model: text-embedding-ada-002
                object: list
                usage:
                  prompt_tokens: 9
                  total_tokens: 9
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    oneOf:
                      - example: No embedding models available for the ${region} region
                description: >-
                  Error message indicating either no models are available in the
                  region or the requested model is not available
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: The provided API key is invalid.
        '429':
          description: Rate Limit Exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Rate limit for public API exceeded
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Internal Server Error
      security:
        - bearerAuth: []
components:
  schemas:
    CreateEmbeddingRequest:
      type: object
      properties:
        input:
          description: >-
            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.
          oneOf:
            - type: string
            - type: array
              items:
                type: string
            - type: array
              items:
                type: number
            - type: array
              items:
                type: array
                items:
                  type: number
        model:
          description: >-
            ID of the model to use. You can use the [List
            models](https://platform.openai.com/docs/api-reference/models/list)
            API to see all of your available models, or see OpenAI's [Model
            overview](https://platform.openai.com/docs/models/overview) for
            descriptions of them.
          oneOf:
            - type: string
            - type: string
              enum:
                - text-embedding-ada-002
                - text-embedding-3-small
                - text-embedding-3-large
        encoding_format:
          description: >-
            The format to return the embeddings in. Can be either `float` or
            `base64`.
          type: string
          enum:
            - float
            - base64
          default: float
        dimensions:
          description: >-
            The number of dimensions the resulting output embeddings should
            have. Only supported in `text-embedding-3` and later models.
          type: integer
          minimum: 1
        user:
          description: >-
            A unique identifier representing your end-user, which can help
            OpenAI to monitor and detect abuse.
          type: string
      required:
        - model
        - input
    CreateEmbeddingResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Embedding'
          description: The list of embeddings generated by the model.
        model:
          type: string
          description: The name of the model used to generate the embedding.
        object:
          type: string
          enum:
            - list
          description: The object type, which is always "list".
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
              description: The number of tokens used for the prompt(s).
            total_tokens:
              type: integer
              description: The total number of tokens used by the request.
          required:
            - prompt_tokens
            - total_tokens
      required:
        - data
        - model
        - object
        - usage
    Embedding:
      type: object
      properties:
        index:
          type: integer
          description: The index of the embedding in the list of embeddings.
        embedding:
          type: array
          items:
            type: number
          description: >-
            The embedding vector, which is a list of floats. The length of
            vector depends on the model as listed in the [embedding
            guide](https://platform.openai.com/docs/guides/embeddings).
        object:
          type: string
          enum:
            - embedding
          description: The object type, which is always "embedding".
      required:
        - index
        - embedding
        - object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````