---
title: "CompletionService"
manual: "TYPO3 LLM Extension"
version: "0.35"
permalink: "https://docs.typo3.org/permalink/netresearch/nr-llm:api-completion-service@0.35"
source: "Api/CompletionService.rst"
modified: "2026-09-16T22:09:16+00:00"
---

# CompletionService

-   **class CompletionService**

    -   *Fully qualified name:* `\Netresearch\NrLlm\Service\Feature\CompletionService`

    High-level text completion with format control.

    -   **complete(string $prompt, ?ChatOptions $options = null) : CompletionResponse**

        Standard text completion.

        -   *param string $prompt:* The prompt text
        -   *param ?ChatOptions $options:* Optional configuration

        *Returns:* CompletionResponse

    -   **completeJson(string $prompt, ?ChatOptions $options = null) : array**

        Completion with JSON output parsing.

        -   *param string $prompt:* The prompt text
        -   *param ?ChatOptions $options:* Optional configuration

        *Returns:* array Parsed JSON data

    -   **completeMarkdown(string $prompt, ?ChatOptions $options = null) : string**

        Completion with markdown formatting.

        -   *param string $prompt:* The prompt text
        -   *param ?ChatOptions $options:* Optional configuration

        *Returns:* string Markdown formatted text

    -   **completeFactual(string $prompt, ?ChatOptions $options = null) : CompletionResponse**

        Low-creativity completion for factual responses.

        -   *param string $prompt:* The prompt text
        -   *param ?ChatOptions $options:* Optional configuration (temperature defaults to 0.1)

        *Returns:* CompletionResponse

    -   **completeCreative(string $prompt, ?ChatOptions $options = null) : CompletionResponse**

        High-creativity completion for creative content.

        -   *param string $prompt:* The prompt text
        -   *param ?ChatOptions $options:* Optional configuration (temperature defaults to 1.2)

        *Returns:* CompletionResponse

    -   **completeStructured(string $prompt, array $schema, ?ChatOptions $options = null) : array**

        Completion validated against a JSON schema from the strict named
        subset ([ADR-126](https://docs.typo3.org/permalink/netresearch/nr-llm:adr-126@0.35)): `type`, `enum`, `const`,
        `pattern`, lengths, numeric bounds, `items`, `properties`/
        `required`/`additionalProperties` and the combinators —
        `$ref` is deliberately out. The schema is pre-flighted BEFORE
        the first provider call (an out-of-subset schema throws code
        `1784500003` instead of costing paid requests), enforced
        provider-natively where the provider can ([ADR-128](https://docs.typo3.org/permalink/netresearch/nr-llm:adr-128@0.35)), validated strictly on the response, and repaired with
        one controlled round-trip on a mismatch.

        -   *param string $prompt:* The prompt text
        -   *param array $schema:* JSON schema inside the strict subset
        -   *param ?ChatOptions $options:* Optional configuration
        -   *throws:*

            InvalidArgumentException on an out-of-subset schema
            (`1784500003`) or when the response still fails the schema
            after one repair attempt (`1784500001`)

        *Returns:* array The decoded, schema-valid JSON payload

    Every method above also exists as a `*ForConfiguration()` variant
    taking a persisted `LlmConfiguration` as its second argument —
    the call then runs with that configuration's provider, model,
    options and skills instead of the system default.
