> ## 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.

# Codestral

> Code-Generierung mit dem Codestral-Modell von Mistral.

<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>

<Warning>
  Derzeit sind keine Mistral-Modelle für die API verfügbar. Schau später nochmal für Updates vorbei.
</Warning>

Erstellt eine Code-Vervollständigung mit dem [Codestral-Modell von Mistral](https://docs.mistral.ai/capabilities/code_generation).

Alle Parameter des [Mistral Fill-in-the-Middle Completion Endpunkts](https://docs.mistral.ai/capabilities/code_generation#fill-in-the-middle-endpoint) werden gemäß den Mistral-Spezifikationen unterstützt.

## Rate Limits

Die Rate Limit für den FIM Completion 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. Jedes Modell hat seine eigene Rate Limit. 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 des Continue AI Code Agents

Die Verwendung des Codestral-Modells in Kombination mit Chat-Completion-Modellen der Langdock API ermöglicht es, den Open-Source-KI-Code-Agenten [Continue (continue.dev)](https://www.continue.dev) vollständig über die Langdock API zu nutzen.

Continue ist als [VS Code-Erweiterung](https://marketplace.visualstudio.com/items?itemName=Continue.continue) und als JetBrains-Erweiterung verfügbar. Um die von Continue verwendeten Modelle anzupassen, bearbeite die Konfigurationsdatei unter `~/.continue/config.yaml` (MacOS / Linux) oder `%USERPROFILE%\.continue\config.yaml` (Windows). Das ältere `config.json` Format ist veraltet.

Nachfolgend findest du ein Beispiel-Setup für die Verwendung von Continue mit dem Codestral-Modell für Autovervollständigung und Claude Sonnet 4.6 und GPT-5.2-Modellen für Chats und Bearbeitungen, die alle über die Langdock API bereitgestellt werden.

```yaml theme={null}
name: Langdock Configuration
version: 1.0.0
schema: v1

models:
  - name: GPT-5.2
    provider: openai
    model: gpt-5.2
    apiBase: https://api.langdock.com/openai/eu/v1
    apiKey: <YOUR_LANGDOCK_API_KEY>
    roles:
      - chat
      - edit

  - name: Claude Sonnet 4.6
    provider: anthropic
    model: claude-sonnet-4-6-default
    apiBase: https://api.langdock.com/anthropic/eu/v1
    apiKey: <YOUR_LANGDOCK_API_KEY>
    roles:
      - chat
      - edit

  - name: Codestral
    provider: mistral
    model: codestral-2501
    apiBase: https://api.langdock.com/mistral/eu/v1
    apiKey: <YOUR_LANGDOCK_API_KEY>
    roles:
      - autocomplete
```

<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 /mistral/{region}/v1/fim/completions
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
    description: Production
security:
  - bearerAuth: []
paths:
  /mistral/{region}/v1/fim/completions:
    post:
      tags:
        - fim
      summary: Fim Completion
      description: FIM completion.
      operationId: fim_completion_v1_fim_completions_post
      parameters:
        - name: region
          in: path
          required: true
          description: The region of the API to use.
          schema:
            type: string
            enum:
              - eu
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FIMCompletionRequest'
            example:
              model: codestral-2501
              prompt: 'function removeSpecialCharactersWithRegex(str: string) {'
              max_tokens: 64
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FIMCompletionResponse'
              example:
                data: asd
                id: 245c52bc936f53ba90327800c73d1c3e
                object: chat.completion
                model: codestral
                usage:
                  prompt_tokens: 16
                  completion_tokens: 102
                  total_tokens: 118
                created: 1732902806
                choices:
                  - index: 0
                    message:
                      content: >2-

                          // Use a regular expression to match any non-alphanumeric character and replace it with an empty string
                          return str.replace(/[^a-zA-Z0-9]/g, '');
                        }


                        // Test the function

                        const inputString = "Hello, World! 123";

                        const outputString =
                        removeSpecialCharactersWithRegex(inputString);

                        console.log(outputString); // Output: "HelloWorld123"
                      prefix: false
                      role: assistant
                    finish_reason: stop
            text/event-stream:
              schema:
                $ref: '#/components/schemas/CompletionEvent'
components:
  schemas:
    FIMCompletionRequest:
      properties:
        model:
          anyOf:
            - type: string
          title: Model
          default: codestral-2501
          description: |-
            ID of the model to use. Only compatible for now with:
              - `codestral-2501`
        temperature:
          anyOf:
            - type: number
              maximum: 1.5
              minimum: 0
          title: Temperature
          description: >-
            What sampling temperature to use, we recommend between 0.0 and 0.7.
            Higher values like 0.7 will make the output more random, while lower
            values like 0.2 will make it more focused and deterministic. We
            generally recommend altering this or `top_p` but not both. The
            default value varies depending on the model you are targeting. Call
            the `/models` endpoint to retrieve the appropriate value.
        top_p:
          type: number
          maximum: 1
          minimum: 0
          title: Top P
          default: 1
          description: >-
            Nucleus sampling, where the model considers the results of the
            tokens with `top_p` probability mass. So 0.1 means only the tokens
            comprising the top 10% probability mass are considered. We generally
            recommend altering this or `temperature` but not both.
        max_tokens:
          anyOf:
            - type: integer
              minimum: 0
          title: Max Tokens
          description: >-
            The maximum number of tokens to generate in the completion. The
            token count of your prompt plus `max_tokens` cannot exceed the
            model's context length.
        stream:
          type: boolean
          title: Stream
          default: false
          description: >-
            Whether to stream back partial progress. If set, tokens will be sent
            as data-only server-side events as they become available, with the
            stream terminated by a data: [DONE] message. Otherwise, the server
            will hold the request open until the timeout or until completion,
            with the response containing the full result as JSON.
        stop:
          anyOf:
            - type: string
            - type: array
              items:
                type: string
          title: Stop
          description: >-
            Stop generation if this token is detected. Or if one of these tokens
            is detected when providing an array
        random_seed:
          anyOf:
            - type: integer
              minimum: 0
          title: Random Seed
          description: >-
            The seed to use for random sampling. If set, different calls will
            generate deterministic results.
        prompt:
          type: string
          title: Prompt
          description: The text/code to complete.
        suffix:
          anyOf:
            - type: string
          title: Suffix
          default: ''
          description: >-
            Optional text/code that adds more context for the model. When given
            a `prompt` and a `suffix` the model will fill what is between them.
            When `suffix` is not provided, the model will simply execute
            completion starting with `prompt`.
        min_tokens:
          anyOf:
            - type: integer
              minimum: 0
          title: Min Tokens
          description: The minimum number of tokens to generate in the completion.
      additionalProperties: false
      type: object
      required:
        - prompt
        - model
      title: FIMCompletionRequest
    FIMCompletionResponse:
      allOf:
        - $ref: '#/components/schemas/ChatCompletionResponse'
        - type: object
          properties:
            model:
              type: string
              example: codestral-latest
    CompletionEvent:
      title: CompletionEvent
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/CompletionChunk'
    ChatCompletionResponse:
      allOf:
        - $ref: '#/components/schemas/ChatCompletionResponseBase'
        - type: object
          title: ChatCompletionResponse
          properties:
            choices:
              type: array
              items:
                $ref: '#/components/schemas/ChatCompletionChoice'
          required:
            - id
            - object
            - data
            - model
            - usage
    CompletionChunk:
      title: CompletionChunk
      type: object
      required:
        - id
        - model
        - choices
      properties:
        id:
          type: string
        object:
          type: string
        created:
          type: integer
        model:
          type: string
        usage:
          $ref: '#/components/schemas/UsageInfo'
        choices:
          type: array
          items:
            $ref: '#/components/schemas/CompletionResponseStreamChoice'
    ChatCompletionResponseBase:
      allOf:
        - $ref: '#/components/schemas/ResponseBase'
        - type: object
          title: ChatCompletionResponseBase
          properties:
            created:
              type: integer
              example: 1702256327
    ChatCompletionChoice:
      title: ChatCompletionChoice
      type: object
      required:
        - index
        - finish_reason
        - message
      properties:
        index:
          type: integer
          example: 0
        message:
          $ref: '#/components/schemas/AssistantMessage'
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - model_length
            - error
            - tool_calls
          example: stop
    UsageInfo:
      title: UsageInfo
      type: object
      properties:
        prompt_tokens:
          type: integer
          example: 16
        completion_tokens:
          type: integer
          example: 34
        total_tokens:
          type: integer
          example: 50
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
    CompletionResponseStreamChoice:
      title: CompletionResponseStreamChoice
      type: object
      required:
        - index
        - delta
        - finish_reason
      properties:
        index:
          type: integer
        delta:
          $ref: '#/components/schemas/DeltaMessage'
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - error
            - tool_calls
    ResponseBase:
      type: object
      title: ResponseBase
      properties:
        id:
          type: string
          example: cmpl-e5cc70bb28c444948073e77776eb30ef
        object:
          type: string
          example: chat.completion
        model:
          type: string
          example: mistral-small-latest
        usage:
          $ref: '#/components/schemas/UsageInfo'
    AssistantMessage:
      properties:
        content:
          title: Content
          anyOf:
            - type: string
            - items:
                $ref: '#/components/schemas/ContentChunk'
              type: array
        tool_calls:
          anyOf:
            - items:
                $ref: '#/components/schemas/ToolCall'
              type: array
          title: Tool Calls
        prefix:
          type: boolean
          title: Prefix
          default: false
        role:
          type: string
          default: assistant
          title: Role
          enum:
            - assistant
      additionalProperties: false
      type: object
      title: AgentMessage
    DeltaMessage:
      title: DeltaMessage
      type: object
      properties:
        role:
          anyOf:
            - type: string
        content:
          anyOf:
            - type: string
            - items:
                $ref: '#/components/schemas/ContentChunk'
              type: array
        tool_calls:
          anyOf:
            - items:
                $ref: '#/components/schemas/ToolCall'
              type: array
    ContentChunk:
      oneOf:
        - $ref: '#/components/schemas/TextChunk'
        - $ref: '#/components/schemas/ImageURLChunk'
      discriminator:
        propertyName: type
        mapping:
          image_url:
            $ref: '#/components/schemas/ImageURLChunk'
          text:
            $ref: '#/components/schemas/TextChunk'
      title: ContentChunk
    ToolCall:
      properties:
        id:
          type: string
          title: Id
          default: 'null'
        type:
          $ref: '#/components/schemas/ToolTypes'
          default: function
        function:
          $ref: '#/components/schemas/FunctionCall'
      additionalProperties: false
      type: object
      required:
        - function
      title: ToolCall
    TextChunk:
      properties:
        type:
          default: text
          enum:
            - text
          title: Type
          type: string
        text:
          type: string
          title: Text
      additionalProperties: false
      type: object
      required:
        - text
      title: TextChunk
    ImageURLChunk:
      properties:
        type:
          type: string
          enum:
            - image_url
          title: Type
          default: image_url
        image_url:
          anyOf:
            - $ref: '#/components/schemas/ImageURL'
            - type: string
          title: Image Url
      additionalProperties: false
      type: object
      required:
        - image_url
      title: ImageURLChunk
      description: '{"type":"image_url","image_url":{"url":"data:image/png;base64,iVBORw0'
    ToolTypes:
      type: string
      enum:
        - function
      title: ToolTypes
    FunctionCall:
      properties:
        name:
          type: string
          title: Name
        arguments:
          title: Arguments
          anyOf:
            - type: object
              additionalProperties: true
            - type: string
      additionalProperties: false
      type: object
      required:
        - name
        - arguments
      title: FunctionCall
    ImageURL:
      properties:
        url:
          type: string
          title: Url
        detail:
          anyOf:
            - type: string
          title: Detail
      additionalProperties: false
      type: object
      required:
        - url
      title: ImageURL
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````