> ## 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 generation using the Codestral model from Mistral.

<Info>
  **⚠️ Using our API via a dedicated deployment?** Just replace `api.langdock.com` with your deployment's base URL: **`<deployment-url>/api/public`**
</Info>

<Warning>
  There are currently no Mistral models available for the API. Check back later for updates.
</Warning>

Creates a code completion using the [Codestral model from Mistral](https://docs.mistral.ai/capabilities/code_generation).

All parameters from the [Mistral fill-in-the-middle Completion endpoint](https://docs.mistral.ai/capabilities/code_generation#fill-in-the-middle-endpoint) are supported according to the Mistral specifications.

## Rate limits

The rate limit for the FIM Completion endpoint is **500 RPM (requests per minute)** and **60,000 TPM (tokens per minute)**. Rate limits are defined at the workspace level - and not at an API key level. Each model has its own rate limit. If you exceed your rate limit, you will receive a `429 Too Many Requests` response.

Please note that the rate limits are subject to change, refer to this documentation for the most up-to-date information.

## Using the Continue AI Code Agent

Using the Codestral model, combined with chat completion models from the Langdock API, makes it possible to use the open-source AI code agent [Continue (continue.dev)](https://www.continue.dev) fully via the Langdock API.

Continue is available as a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=Continue.continue) and as a JetBrains extension. To customize the models used by Continue, you can edit the configuration file at `~/.continue/config.json` (MacOS / Linux) or `%USERPROFILE%\.continue\config.json` (Windows).

Below is an example setup for using Continue with the Codestral model for autocomplete and Claude Sonnet 4.6 and GPT-5.2 models for chats and edits, all served from the Langdock API.

```json theme={null}
{
  "models": [
    {
      "title": "GPT-5.2",
      "provider": "openai",
      "model": "gpt-5.2",
      "apiKey": "<YOUR_LANGDOCK_API_KEY>",
      "apiBase": "https://api.langdock.com/openai/eu/v1"
    },
    {
      "title": "Claude Sonnet 4.6",
      "provider": "anthropic",
      "model": "claude-sonnet-4-6-default",
      "apiKey": "<YOUR_LANGDOCK_API_KEY>",
      "apiBase": "https://api.langdock.com/anthropic/eu/v1"
    }
  ],
  "tabAutocompleteModel": {
    "title": "Codestral",
    "provider": "mistral",
    "model": "codestral-2501",
    "apiKey": "<YOUR_LANGDOCK_API_KEY>",
    "apiBase": "https://api.langdock.com/mistral/eu/v1"
  }
  /* ... other configuration ... */
}
```

<Info>
  Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on [API Key Best Practices](/en/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
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"

````