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

# Sunflower Inference

> Professional Sunflower inference endpoint for multilingual chat completions.

**Deprecated**: use POST /tasks/chat/completions instead.

This endpoint provides access to Sunbird AI's Sunflower model, specialized in:
- Multilingual conversations in Ugandan languages (Luganda, Acholi, Ateso, etc.)
- Cross-lingual translations and explanations
- Cultural context understanding
- Educational content in local languages

Features:
- Automatic retry with exponential backoff
- Context-aware responses
- Usage tracking and monitoring
- Support for custom system messages
- Message history management

Args:

    request: The FastAPI request object (required for rate limiting).
    chat_request: The chat request containing messages and parameters.
    background_tasks: FastAPI background tasks for async operations.
    current_user: The authenticated user (enforces authentication).
    service: The inference service instance.

Returns:

    SunflowerChatResponse containing the AI's response and usage stats.

Raises:

    BadRequestError: For validation errors.
    ValidationError: For invalid message format.
    ServiceUnavailableError: If the model is loading or request times out.
    ExternalServiceError: For empty model response or unexpected errors.

Example:

    Request body with message history:

    {
        "messages": [
            {"role": "system", "content": "You are Sunflower..."},
            {"role": "user", "content": "Translate 'How are you?' to Luganda."},
            {"role": "assistant", "content": "In Luganda, 'How are you?' is 'Oli otya?'."},
            {"role": "user", "content": "How do I say 'Good morning' in Acholi?"}
        ],
        "model_type": "qwen",
        "temperature": 0.3
    }

    Response:

    {
        "content": "In Acholi, 'Good morning' is 'Icwiny atir'.",
        "model_type": "qwen",
        "usage": {"completion_tokens": 15, "prompt_tokens": 50, "total_tokens": 65},
        "processing_time": 2.5,
        "inference_time": 2.0,
        "message_count": 5
    }



## OpenAPI

````yaml api-reference/openapi-legacy.json POST /tasks/sunflower_inference
openapi: 3.1.0
info:
  title: Sunbird AI API (Legacy / Deprecated)
  description: >

    Welcome to the Sunbird AI API documentation. The Sunbird AI API provides
    access to

    Sunbird's language models and AI services for Ugandan languages.


    ## Supported Languages

    **English**, **Acholi**, **Ateso**, **Luganda**, **Lugbara**,
    **Runyankole**, **Swahili**

    and **20+** more Ugandan languages supported via sunflower.


    ## Getting Started

    You can checkout the [usage guide](https://salt.sunbird.ai/API/) for a full
    tutorial.


    For quickstart tutorials, visit our

    [GitHub
    repository](https://github.com/SunbirdAI/sunbird-ai-api/blob/main/docs/tutorial.md)


    ### Authentication


    #### Signing Up

    If you don't already have an account, use the `/auth/register` endpoint to
    create one.


    #### Getting an Access Token

    Authentication is done via a Bearer token. Use the `/auth/token` endpoint to
    get your

    access token. This token lasts for 7 days.


    Use the `Authorize` button below to login and access the protected
    endpoints.


    ## API Endpoints


    ### Translation

    - **`POST /tasks/translate`** - Translate text between 32 Ugandan and East
    African
      languages using the Sunflower model. Languages are accepted as ISO codes (`lug`)
      or full names (`Luganda`); `source_language` is optional (auto-detected when
      omitted). Translation works between any pair of supported languages.

    ### Language Detection

    - **`POST /tasks/language_id`** - Auto-detect the language of text input
      (supports Acholi, Ateso, English, Luganda, Lugbara, Runyankole)

    ### Speech-to-Text (STT)

    - **`POST /tasks/audio/transcriptions`** - Unified STT endpoint
    (OpenAI-style).
      - Accepts an uploaded audio file (`audio`) or a GCS object (`gcs_blob_name`).
      - `platform`: `modal` (default, Whisper large-v3) or `runpod`.
      - RunPod options: `adapter` (language adapter), `whisper`, `recognise_speakers`
        (diarization), and the `org` organization workflow.
      - `language`: 3-letter code (e.g. `eng`, `lug`) or full name; improves accuracy.
        Supports WAV, MP3, OGG, M4A, and more. Auto-detects when omitted.
      - **Deprecated** → use `POST /tasks/audio/transcriptions`:
        - `POST /tasks/stt`, `POST /tasks/stt_from_gcs`, `POST /tasks/org/stt`,
          `POST /tasks/modal/stt`

    ### Text-to-Speech (TTS)

    - **`POST /tasks/audio/speech`** - Unified single-synthesis endpoint.
      - `model`: `orpheus-3b-tts` (default) or `spark-tts`; `platform`: `modal` or `runpod`.
      - `voice`: speaker tag/name. `response_mode`: `url` (default), `stream`, or `both`
        (`stream`/`both` require `spark-tts` on `modal`).
      - Orpheus tuning: `language`, `temperature`, `top_p`, `repetition_penalty`,
        `max_tokens`, `seed`. Returns a signed GCP Storage URL.
    - **`POST /tasks/audio/speech/batch`** - Batch synthesis (orpheus-3b-tts
    only), 1-128 items.

    - **`GET /tasks/voice/speakers`** - List voices for a `model` (optional
    orpheus `language`).
      - **orpheus-3b-tts** covers 20 African languages: Acholi (`ach`), Afrikaans (`afr`),
        English (`eng`), Ewe (`ewe`), Fulah (`ful`), Hausa (`hau`), Igbo (`ibo`), Kikuyu (`kik`),
        Kinyarwanda (`kin`), Lugbara (`lgg`), Lingala (`lin`), Luganda (`lug`), Luo (`luo`),
        Runyankole (`nyn`), Sesotho (`sot`), Swahili (`swa`), Ateso (`teo`), Setswana (`tsn`),
        Xhosa (`xho`), Yoruba (`yor`). A few (`lgg`, `sot`, `tsn`) are in the training mix but
        expose no individual voice IDs yet. Full per-speaker catalog: see the
        [tutorial](https://github.com/SunbirdAI/sunbird-ai-api/blob/main/docs/tutorial.md)
        or call `GET /tasks/voice/speakers`.
    - **`GET /tasks/audio/speech/url`** - Refresh an expired signed URL for a
    stored audio object.
      - **Deprecated** → superseded by the unified endpoints above:
        - `POST /tasks/modal/tts`, `POST /tasks/runpod/tts`,
          `POST /tasks/modal/orpheus/tts` → `POST /tasks/audio/speech`
        - `POST /tasks/modal/tts/stream` → `/tasks/audio/speech` (`response_mode=stream`)
        - `POST /tasks/modal/tts/stream-with-url` → `/tasks/audio/speech` (`response_mode=both`)
        - `POST /tasks/modal/orpheus/tts/batch` → `POST /tasks/audio/speech/batch`
        - `GET /tasks/modal/tts/speakers`, `GET /tasks/modal/orpheus/speakers`,
          `GET /tasks/modal/orpheus/speakers/{language}` → `GET /tasks/voice/speakers`
        - `GET /tasks/modal/tts/refresh-url` → `GET /tasks/audio/speech/url`

    ### Inference (Sunflower Chat)

    - **`POST /tasks/chat/completions`** - OpenAI-compatible chat completions
    (Sunflower model).
      Supports single instructions, multi-turn conversations, and SSE streaming (`stream: true`).
      Use model `Sunbird/Sunflower-14B`.
      - **Deprecated** → superseded by the unified endpoint above:
        - `POST /tasks/sunflower_inference` → `POST /tasks/chat/completions`
        - `POST /tasks/sunflower_simple` → `POST /tasks/chat/completions` (send the instruction as a single user message)

    ### File Upload

    - **`POST /tasks/generate-upload-url`** - Generate signed URLs for direct
    client uploads to GCP Storage
      - Supports audio files, images, and other content types
      - Includes path traversal protection and input validation
      - Returns temporary signed URL valid for 30 minutes

    ### WhatsApp Integration (Webhooks)

    - **`POST /tasks/webhook`** - Handle incoming WhatsApp Business API messages

    - **`GET /tasks/webhook`** - Verify webhook endpoint ownership for WhatsApp


    ### Legacy Endpoints

    - **`POST /tasks/summarise`** - *(Deprecated)* Anonymized text summarization
    (use Sunflower inference instead)


    ## Rate Limiting

    API endpoints are rate-limited to ensure fair usage. Authentication is
    required for most endpoints.
  version: 0.1.0
servers:
  - url: https://api.sunbird.ai
security: []
tags:
  - name: legacy/deprecated
    description: >-
      Deprecated endpoints retained for backward compatibility. Each is
      superseded by a unified endpoint — see its Deprecation/Sunset/Link
      response headers — and will be removed after the sunset date. Do not build
      new integrations against these.
paths:
  /tasks/sunflower_inference:
    post:
      tags:
        - legacy/deprecated
      summary: Sunflower Inference
      description: >-
        Professional Sunflower inference endpoint for multilingual chat
        completions.


        **Deprecated**: use POST /tasks/chat/completions instead.


        This endpoint provides access to Sunbird AI's Sunflower model,
        specialized in:

        - Multilingual conversations in Ugandan languages (Luganda, Acholi,
        Ateso, etc.)

        - Cross-lingual translations and explanations

        - Cultural context understanding

        - Educational content in local languages


        Features:

        - Automatic retry with exponential backoff

        - Context-aware responses

        - Usage tracking and monitoring

        - Support for custom system messages

        - Message history management


        Args:

            request: The FastAPI request object (required for rate limiting).
            chat_request: The chat request containing messages and parameters.
            background_tasks: FastAPI background tasks for async operations.
            current_user: The authenticated user (enforces authentication).
            service: The inference service instance.

        Returns:

            SunflowerChatResponse containing the AI's response and usage stats.

        Raises:

            BadRequestError: For validation errors.
            ValidationError: For invalid message format.
            ServiceUnavailableError: If the model is loading or request times out.
            ExternalServiceError: For empty model response or unexpected errors.

        Example:

            Request body with message history:

            {
                "messages": [
                    {"role": "system", "content": "You are Sunflower..."},
                    {"role": "user", "content": "Translate 'How are you?' to Luganda."},
                    {"role": "assistant", "content": "In Luganda, 'How are you?' is 'Oli otya?'."},
                    {"role": "user", "content": "How do I say 'Good morning' in Acholi?"}
                ],
                "model_type": "qwen",
                "temperature": 0.3
            }

            Response:

            {
                "content": "In Acholi, 'Good morning' is 'Icwiny atir'.",
                "model_type": "qwen",
                "usage": {"completion_tokens": 15, "prompt_tokens": 50, "total_tokens": 65},
                "processing_time": 2.5,
                "inference_time": 2.0,
                "message_count": 5
            }
      operationId: sunflower_inference_tasks_sunflower_inference_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SunflowerChatRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SunflowerChatResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      deprecated: true
      security:
        - OAuth2PasswordBearer: []
components:
  schemas:
    SunflowerChatRequest:
      properties:
        messages:
          items:
            $ref: '#/components/schemas/SunflowerChatMessage'
          type: array
          title: Messages
          description: List of conversation messages
        model_type:
          type: string
          title: Model Type
          description: 'Model type: ''qwen'''
          default: qwen
        temperature:
          type: number
          maximum: 2
          minimum: 0
          title: Temperature
          description: Sampling temperature
          default: 0.3
        stream:
          type: boolean
          title: Stream
          description: Whether to stream the response
          default: false
        system_message:
          anyOf:
            - type: string
            - type: 'null'
          title: System Message
          description: Custom system message
      type: object
      required:
        - messages
      title: SunflowerChatRequest
      description: |-
        Request model for Sunflower chat inference.

        Attributes:
            messages: List of conversation messages.
            model_type: The model to use ('qwen').
            temperature: Sampling temperature (0.0 to 2.0).
            stream: Whether to stream the response.
            system_message: Optional custom system message.
    SunflowerChatResponse:
      properties:
        content:
          type: string
          title: Content
          description: The AI's response
        model_type:
          type: string
          title: Model Type
          description: Model used for inference
        usage:
          $ref: '#/components/schemas/SunflowerUsageStats'
          description: Token usage statistics
        processing_time:
          type: number
          title: Processing Time
          description: Total processing time in seconds
        inference_time:
          type: number
          title: Inference Time
          description: Model inference time in seconds
          default: 0
        message_count:
          type: integer
          title: Message Count
          description: Number of messages processed
          default: 0
      type: object
      required:
        - content
        - model_type
        - usage
        - processing_time
      title: SunflowerChatResponse
      description: |-
        Response model from Sunflower chat inference.

        Attributes:
            content: The AI's response text.
            model_type: The model used for inference.
            usage: Token usage statistics.
            processing_time: Total processing time in seconds.
            inference_time: Model inference time in seconds.
            message_count: Number of messages processed.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SunflowerChatMessage:
      properties:
        role:
          type: string
          title: Role
          description: 'Message role: ''system'', ''user'', or ''assistant'''
        content:
          type: string
          title: Content
          description: Message content
      type: object
      required:
        - role
        - content
      title: SunflowerChatMessage
      description: |-
        A single message in the chat conversation.

        Attributes:
            role: The role of the message sender ('system', 'user', or 'assistant').
            content: The content of the message.
    SunflowerUsageStats:
      properties:
        completion_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Completion Tokens
          description: Number of tokens in the completion
        prompt_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Prompt Tokens
          description: Number of tokens in the prompt
        total_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Total Tokens
          description: Total number of tokens used
      type: object
      title: SunflowerUsageStats
      description: |-
        Token usage statistics from the inference.

        Attributes:
            completion_tokens: Number of tokens in the completion.
            prompt_tokens: Number of tokens in the prompt.
            total_tokens: Total number of tokens used.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    OAuth2PasswordBearer:
      type: oauth2
      flows:
        password:
          scopes: {}
          tokenUrl: /auth/token

````