{
  "openapi": "3.1.0",
  "info": {
    "title": "EvoLink Auto - 지능형 모델 선택",
    "description": "지능형 모델 라우팅 기능, 시스템이 자동으로 가장 적합한 AI 모델을 선택합니다",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://direct.evolink.ai",
      "description": "프로덕션 (권장)"
    },
    {
      "url": "https://api.evolink.ai",
      "description": "대체 URL"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "지능형 모델 라우팅",
        "description": "시스템이 자동으로 가장 적합한 모델을 선택하여 요청을 처리합니다",
        "operationId": "createChatCompletionAuto",
        "tags": [
          "지능형 라우팅"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutoRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "요청 성공",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              }
            }
          },
          "400": {
            "description": "잘못된 요청 매개변수",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 400,
                    "message": "Invalid request parameters",
                    "type": "invalid_request_error"
                  }
                }
              }
            }
          },
          "401": {
            "description": "인증되지 않음, 유효하지 않거나 만료된 토큰",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 401,
                    "message": "Invalid or expired token",
                    "type": "authentication_error"
                  }
                }
              }
            }
          },
          "402": {
            "description": "할당량 부족, 충전 필요",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 402,
                    "message": "Insufficient quota",
                    "type": "insufficient_quota_error",
                    "fallback_suggestion": "https://evolink.ai/dashboard/credits"
                  }
                }
              }
            }
          },
          "403": {
            "description": "접근 거부",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 403,
                    "message": "Access denied for this feature",
                    "type": "permission_error"
                  }
                }
              }
            }
          },
          "429": {
            "description": "요청 빈도 초과",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 429,
                    "message": "Rate limit exceeded",
                    "type": "rate_limit_error",
                    "fallback_suggestion": "retry after 60 seconds"
                  }
                }
              }
            }
          },
          "500": {
            "description": "내부 서버 오류",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 500,
                    "message": "Internal server error",
                    "type": "internal_server_error",
                    "fallback_suggestion": "try again later"
                  }
                }
              }
            }
          },
          "502": {
            "description": "업스트림 서비스 오류",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 502,
                    "message": "Upstream AI service unavailable",
                    "type": "upstream_error",
                    "fallback_suggestion": "try again later"
                  }
                }
              }
            }
          },
          "503": {
            "description": "서비스 일시적으로 사용 불가",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 503,
                    "message": "Service temporarily unavailable",
                    "type": "service_unavailable_error",
                    "fallback_suggestion": "retry after 30 seconds"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AutoRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "지능형 라우팅 사용",
            "enum": [
              "evolink/auto"
            ],
            "default": "evolink/auto",
            "example": "evolink/auto"
          },
          "messages": {
            "type": "array",
            "description": "대화 메시지 목록",
            "items": {
              "$ref": "#/components/schemas/MessageInput"
            },
            "minItems": 1,
            "example": [
              {
                "role": "user",
                "content": "인공지능의 발전 역사를 소개해 주세요"
              }
            ]
          },
          "temperature": {
            "type": "number",
            "description": "샘플링 온도, 출력의 무작위성을 제어합니다\n\n**설명**:\n- 낮은 값(예: 0.2): 더 확실하고 집중된 출력\n- 높은 값(예: 1.5): 더 무작위적이고 창의적인 출력",
            "minimum": 0,
            "maximum": 2,
            "example": 0.7
          },
          "top_p": {
            "type": "number",
            "description": "핵 샘플링(Nucleus Sampling) 매개변수\n\n**설명**:\n- 누적 확률 상위 몇 %의 토큰에서 샘플링할지 제어합니다\n- 예를 들어 0.9는 누적 확률이 90%에 도달하는 토큰 중에서 선택합니다\n- 기본값: 1.0 (모든 토큰 고려)\n\n**권장 사항**: temperature와 top_p를 동시에 조정하지 마세요",
            "minimum": 0,
            "maximum": 1,
            "example": 0.9
          },
          "top_k": {
            "type": "integer",
            "description": "Top-K 샘플링 매개변수\n\n**설명**:\n- 예를 들어 10은 매 샘플링 시 확률이 가장 높은 10개의 토큰만 고려하도록 제한합니다\n- 값이 작을수록 출력이 더 집중됩니다\n- 기본값은 제한 없음",
            "minimum": 1,
            "example": 40
          },
          "stream": {
            "type": "boolean",
            "description": "스트리밍 방식으로 응답을 반환할지 여부\n\n- `true`: 스트리밍 반환, 청크 단위로 실시간 콘텐츠 반환\n- `false`: 전체 응답을 기다린 후 한 번에 반환",
            "default": false,
            "example": false
          }
        }
      },
      "MessageInput": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "description": "메시지 역할",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string",
            "description": "메시지 내용"
          }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "채팅 완성의 고유 식별자",
            "example": "chatcmpl-20260308112637503180122ABCD1234"
          },
          "model": {
            "type": "string",
            "description": "실제 사용된 모델 이름",
            "example": "gpt-5.4"
          },
          "object": {
            "type": "string",
            "enum": [
              "chat.completion"
            ],
            "description": "응답 유형",
            "example": "chat.completion"
          },
          "created": {
            "type": "integer",
            "description": "생성 타임스탬프",
            "example": 1741428397
          },
          "choices": {
            "type": "array",
            "description": "대화에서 생성된 선택 목록",
            "items": {
              "$ref": "#/components/schemas/Choice"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "Choice": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer",
            "description": "이 선택의 인덱스",
            "example": 0
          },
          "message": {
            "$ref": "#/components/schemas/AssistantMessage"
          },
          "finish_reason": {
            "type": "string",
            "description": "완료가 종료된 이유",
            "enum": [
              "stop",
              "length",
              "content_filter"
            ],
            "example": "stop"
          }
        }
      },
      "AssistantMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "description": "메시지 발신자의 역할",
            "enum": [
              "assistant"
            ],
            "example": "assistant"
          },
          "content": {
            "type": "string",
            "description": "AI의 응답 내용",
            "example": "인공지능의 발전 역사는 1950년대로 거슬러 올라갑니다..."
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "description": "메시지 역할"
          },
          "content": {
            "type": "string",
            "description": "메시지 내용"
          }
        }
      },
      "Usage": {
        "type": "object",
        "description": "토큰 사용 통계",
        "properties": {
          "prompt_tokens": {
            "type": "integer",
            "description": "입력의 토큰 수",
            "example": 15
          },
          "completion_tokens": {
            "type": "integer",
            "description": "출력의 토큰 수",
            "example": 120
          },
          "total_tokens": {
            "type": "integer",
            "description": "총 토큰 수",
            "example": 135
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer",
                "description": "HTTP 상태 오류 코드"
              },
              "message": {
                "type": "string",
                "description": "오류 메시지"
              },
              "type": {
                "type": "string",
                "description": "오류 유형"
              },
              "param": {
                "type": "string",
                "description": "관련 매개변수 이름"
              },
              "fallback_suggestion": {
                "type": "string",
                "description": "오류 처리를 위한 제안"
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "## 모든 API는 Bearer Token 인증이 필요합니다 ##\n\n**API Key 받기:**\n\n[API Key 관리 페이지](https://evolink.ai/dashboard/keys)를 방문하여 API Key를 받으세요\n\n**요청 헤더에 추가:**\n```\nAuthorization: Bearer YOUR_API_KEY\n```",
        "bearerFormat": "sk-evo-xxxxxxxxxx"
      }
    }
  }
}
