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

# Optimize an article for SEO and save the result

> Optimizes each target language of the article and persists the patched fields plus the recomputed `seo.perLanguage` metrics. When `languages` is omitted, every language present on the article is optimized. `title`, `summary` and `content` default to true; `tags` defaults to false.



## OpenAPI

````yaml /api-reference/ai-cms/openapi-TAGTEST.json post /ai/optimizeArticle
openapi: 3.1.0
info:
  title: Blog API
  version: 1.0.0
servers:
  - url: https://api.octaviatech.app/cms
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Tags
    description: Tag management endpoints
paths:
  /ai/optimizeArticle:
    post:
      tags:
        - AI Automation
      summary: Optimize an article for SEO and save the result
      description: >-
        Optimizes each target language of the article and persists the patched
        fields plus the recomputed `seo.perLanguage` metrics. When `languages`
        is omitted, every language present on the article is optimized. `title`,
        `summary` and `content` default to true; `tags` defaults to false.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - articleId
              properties:
                articleId:
                  type: string
                  example: '{{objectId}}'
                primaryKeyword:
                  type: string
                  description: >-
                    Keyword to target; falls back to the article's stored
                    per-language primary keyword
                  example: intermittent fasting
                languages:
                  type: array
                  items:
                    type: string
                  description: >-
                    Language codes to optimize. Ignored codes that the article
                    does not have. Defaults to all available languages.
                  example:
                    - en
                    - es
                fields:
                  type: object
                  additionalProperties: false
                  description: Per-field opt-in. Unspecified fields keep their defaults.
                  properties:
                    title:
                      type: boolean
                      default: true
                    summary:
                      type: boolean
                      default: true
                    content:
                      type: boolean
                      default: true
                    tags:
                      type: boolean
                      default: false
            examples:
              Basic:
                value:
                  articleId: '{{objectId}}'
                  primaryKeyword: intermittent fasting
                  languages:
                    - en
                  fields:
                    title: true
                    content: true
      responses:
        '200':
          description: OK (optimized and saved)
          content:
            application/json:
              example:
                success: true
                statusCode: 200
                message: AI SEO optimization generated and saved successfully
                data:
                  articleId: '{{objectId}}'
                  patched:
                    en:
                      title: …
                      summary: …
                      contentHtml: <p>…</p>
                      tags:
                        - fasting
                  seo:
                    before:
                      en:
                        score: 62
                    after:
                      en:
                        score: 91
                  saved: true
              schema:
                allOf:
                  - $ref: '#/components/schemas/Envelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/AiArticleSeoResult'
        '400':
          description: articleId missing
        '401':
          description: Unauthorized
        '403':
          description: Forbidden (role not allowed)
        '404':
          description: Article not found
        '406':
          description: No languages available to optimize for this article
        '426':
          description: Upgrade required (ai_tokens limit exceeded)
        '500':
          description: Failed to optimize article SEO
      security:
        - ApiKeyAuth: []
components:
  schemas:
    Envelope:
      type: object
      properties:
        success:
          type: boolean
        statusCode:
          type: integer
        message:
          type: string
        data:
          type:
            - object
            - 'null'
      required:
        - success
        - statusCode
        - message
        - data
    AiArticleSeoResult:
      type: object
      properties:
        articleId:
          $ref: '#/components/schemas/ObjectId'
        patched:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/AiArticlePatch'
        seo:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/SeoAnalysis'
        saved:
          type: boolean
    ObjectId:
      type: string
      pattern: ^[a-fA-F0-9]{24}$
    AiArticlePatch:
      type: object
      properties:
        title:
          type: string
        summary:
          type: string
        contentHtml:
          type: string
        tags:
          type: array
          items:
            type: string
    SeoAnalysis:
      type: object
      properties:
        score:
          type: number
        potentialScore:
          type: number
        scores:
          type: object
          properties:
            titleMeta:
              type: number
            structure:
              type: number
            keywords:
              type: number
            content:
              type: number
            readability:
              type: number
            links:
              type: number
            images:
              type: number
            technical:
              type: number
        stats:
          type: object
          properties:
            wordCount:
              type: integer
            keywordDensity:
              type: number
            readabilityScore:
              type: number
            readabilityLevel:
              type: string
            totalImages:
              type: integer
            totalLinks:
              type: integer
            headingsCount:
              type: integer
        topKeywords:
          type: array
          items:
            type: object
            properties:
              term:
                type: string
              count:
                type: integer
              inTitle:
                type: boolean
        allKeywords:
          type: array
          items:
            type: object
            properties:
              term:
                type: string
              count:
                type: integer
              density:
                type: number
              inTitle:
                type: boolean
              inHeadings:
                type: integer
        issues:
          type: object
          properties:
            critical:
              type: array
              items:
                type: string
            warnings:
              type: array
              items:
                type: string
            criticalCount:
              type: integer
            warningCount:
              type: integer
        checks:
          type: object
          properties:
            hasH1:
              type: boolean
            hasImages:
              type: boolean
            hasLinks:
              type: boolean
            hasGoodReadability:
              type: boolean
            urlOptimized:
              type: boolean
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````