{
  "openapi": "3.0.3",
  "info": {
    "title": "ChinaVisaCalc — Official Public REST & MCP API",
    "version": "1.0.0",
    "description": "Stateless read-only compliance engines for China SAFEA Circular [2017] 40 9-dimension 120-point Category A/B/C work permits, Feb 2026 municipal 6x salary benchmarks, dual-statute job transfer timelines (10 working days SAFEA + 15 calendar days Art. 50), 21-country Hague Apostille rules, and expatriate IIT tax optimization through 2027-12-31.",
    "contact": {
      "name": "ChinaVisaCalc",
      "url": "https://chinavisacalc.com",
      "email": "contact@chinavisacalc.com"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "externalDocs": {
    "description": "ChinaVisaCalc Official Portal",
    "url": "https://chinavisacalc.com"
  },
  "servers": [
    {
      "url": "https://chinavisacalc.com",
      "description": "Production Edge & Cloud Run"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "paths": {
    "/api/v1/me": {
      "get": {
        "operationId": "verifyApiConnection",
        "summary": "Verify ChinaVisaCalc Connection & Tool Count",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "BearerAuth": []
          },
          {}
        ],
        "responses": {
          "200": {
            "description": "Service status and MCP tool inventory count"
          }
        }
      }
    },
    "/api/v1/tools": {
      "get": {
        "operationId": "listChinaVisaCalcTools",
        "summary": "List All ChinaVisaCalc Tools",
        "responses": {
          "200": {
            "description": "JSON schema inventory of all 8 ChinaVisaCalc tools"
          }
        }
      }
    },
    "/api/v1/tools/calculate_safea_work_permit_points": {
      "post": {
        "operationId": "calculate_safea_work_permit_points",
        "summary": "China SAFEA Category A/B/C Work Permit Points & Eligibility Scorer (120-Point Matrix)",
        "description": "Evaluate foreign applicant eligibility across the official 9-dimension 120-point SAFEA Circular [2017] 40 matrix (110 national + 10 local encouragement, including Direct Category B-1 check), native English teacher track, or WFOE entrepreneur track.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "track": {
                    "type": "string",
                    "enum": [
                      "points",
                      "teacher",
                      "entrepreneur"
                    ],
                    "description": "Applicant track: standard points rubric, native language teacher, or WFOE investor/founder."
                  },
                  "cityTier": {
                    "type": "string",
                    "enum": [
                      "tier1_megacities",
                      "tier2_standard"
                    ],
                    "description": "Optional municipality context metadata (matrix salary brackets follow nationwide RMB tiers)."
                  },
                  "salary": {
                    "type": "string",
                    "enum": [
                      "salary_450k",
                      "salary_350k",
                      "salary_250k",
                      "salary_150k",
                      "salary_70k",
                      "salary_50k",
                      "salary_low"
                    ],
                    "description": "Dimension 1 (Max 20 pts): Contracted gross annual RMB salary tier."
                  },
                  "education": {
                    "type": "string",
                    "enum": [
                      "edu_phd",
                      "edu_master",
                      "edu_bachelor",
                      "edu_associate"
                    ],
                    "description": "Dimension 2 (Max 20 pts): Highest authenticated academic degree or equivalent vocational skill credential."
                  },
                  "experience": {
                    "type": "string",
                    "enum": [
                      "exp_17plus",
                      "exp_16",
                      "exp_15",
                      "exp_14",
                      "exp_13",
                      "exp_12",
                      "exp_11",
                      "exp_10",
                      "exp_9",
                      "exp_8",
                      "exp_7",
                      "exp_6",
                      "exp_5",
                      "exp_4",
                      "exp_3",
                      "exp_2",
                      "exp_under2",
                      "exp_10plus",
                      "exp_5to9",
                      "exp_2to4"
                    ],
                    "description": "Dimension 3 (Max 20 pts): Post-graduation full-time relevant work experience (<2 yrs=0; 2 yrs=5; +1/yr up to 20 at >=17 yrs)."
                  },
                  "experienceYears": {
                    "type": "number",
                    "description": "Optional exact integer years of post-graduation relevant experience (overrides `experience` enum if provided)."
                  },
                  "workDuration": {
                    "type": "string",
                    "enum": [
                      "dur_9plus",
                      "dur_6to8",
                      "dur_3to5",
                      "dur_under3"
                    ],
                    "description": "Dimension 4 (Max 15 pts): Annual working months in China (>=9m=15, 6-8m=10, 3-5m=5, <3m=0). Defaults to dur_9plus."
                  },
                  "age": {
                    "type": "string",
                    "enum": [
                      "age_26_45",
                      "age_18_25",
                      "age_46_55",
                      "age_56_60",
                      "age_over60"
                    ],
                    "description": "Dimension 7 (Max 15 pts): Applicant age bracket at submission."
                  },
                  "chinese": {
                    "type": "string",
                    "enum": [
                      "hsk_5_6",
                      "hsk_4",
                      "hsk_3",
                      "hsk_2",
                      "hsk_1",
                      "hsk_none"
                    ],
                    "description": "Dimension 5 (Max 5 pts): HSK level (HSK 5+/Chinese degree/former PRC=5, HSK 4=4, HSK 3=3, HSK 2=2, HSK 1=1, None=0)."
                  },
                  "location": {
                    "type": "string",
                    "enum": [
                      "loc_western",
                      "loc_standard"
                    ],
                    "description": "Dimension 6 (Max 10 pts): loc_western (Western/Northeast/Key Assistance/FTP = +10) or loc_standard (0)."
                  },
                  "localIncentive": {
                    "type": "string",
                    "enum": [
                      "local_10",
                      "local_5",
                      "local_0"
                    ],
                    "description": "Dimension 9 (Max 10 pts): Provincial/municipal urgent talent encouragement (local_0=0, local_5=5, local_10=10)."
                  },
                  "bonus": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "bonus_top100_uni",
                        "bonus_fortune500_exp",
                        "bonus_patent_ip",
                        "bonus_china_5yrs"
                      ]
                    },
                    "description": "Dimension 8 (Max 5 pts TOTAL, capped/non-stackable): World Top 100 uni, Fortune Global 500, patent/IP, or >=5 yrs in China."
                  },
                  "nativeCountry": {
                    "type": "boolean",
                    "description": "Teacher track: passport from US, UK, CA, AU, NZ, IE, or ZA."
                  },
                  "teflCertified": {
                    "type": "boolean",
                    "description": "Teacher track: holds 120-hour accredited TEFL/TESOL/CELTA or Education/English degree."
                  },
                  "twoYearsTeachingExp": {
                    "type": "boolean",
                    "description": "Teacher track: 2+ years verifiable post-grad teaching."
                  },
                  "registeredCapital": {
                    "type": "string",
                    "enum": [
                      "cap_1m",
                      "cap_low"
                    ],
                    "description": "Entrepreneur track: registered corporate capital bracket."
                  },
                  "hasChineseEmployee": {
                    "type": "boolean",
                    "description": "Entrepreneur track: active Chinese staff with social security."
                  },
                  "hasPhysicalOffice": {
                    "type": "boolean",
                    "description": "Entrepreneur track: commercial lease filed with housing bureau."
                  }
                },
                "required": [
                  "track"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/optimize_work_permit_score_deficit": {
      "post": {
        "operationId": "optimize_work_permit_score_deficit",
        "summary": "China Work Permit Score Deficit Analyzer & Upgrade Levers",
        "description": "Diagnose exact point gaps below Category B (60/120) or Category A (85/120) thresholds under SAFEA Circular [2017] 40 (including Direct B-1 check) and rank accurate upgrade levers (work duration, HSK max 5 pts, World Top 100 / Fortune 500 capped 5 pts, Western/FTP +10 pts, provincial encouragement, and exact salary bracket step-ups).",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "cityTier": {
                    "type": "string",
                    "enum": [
                      "tier1_megacities",
                      "tier2_standard"
                    ],
                    "description": "Optional municipality context metadata."
                  },
                  "salary": {
                    "type": "string",
                    "enum": [
                      "salary_450k",
                      "salary_350k",
                      "salary_250k",
                      "salary_150k",
                      "salary_70k",
                      "salary_50k",
                      "salary_low"
                    ],
                    "description": "Current gross annual RMB salary tier from employment contract."
                  },
                  "education": {
                    "type": "string",
                    "enum": [
                      "edu_phd",
                      "edu_master",
                      "edu_bachelor",
                      "edu_associate"
                    ],
                    "description": "Current highest authenticated academic degree or equivalent vocational skill credential."
                  },
                  "experience": {
                    "type": "string",
                    "enum": [
                      "exp_17plus",
                      "exp_16",
                      "exp_15",
                      "exp_14",
                      "exp_13",
                      "exp_12",
                      "exp_11",
                      "exp_10",
                      "exp_9",
                      "exp_8",
                      "exp_7",
                      "exp_6",
                      "exp_5",
                      "exp_4",
                      "exp_3",
                      "exp_2",
                      "exp_under2",
                      "exp_10plus",
                      "exp_5to9",
                      "exp_2to4"
                    ],
                    "description": "Current post-graduation relevant full-time work experience years."
                  },
                  "experienceYears": {
                    "type": "number",
                    "description": "Optional exact integer years of post-graduation relevant experience."
                  },
                  "workDuration": {
                    "type": "string",
                    "enum": [
                      "dur_9plus",
                      "dur_6to8",
                      "dur_3to5",
                      "dur_under3"
                    ],
                    "description": "Current annual working time bracket in China (Max 15 pts)."
                  },
                  "age": {
                    "type": "string",
                    "enum": [
                      "age_26_45",
                      "age_18_25",
                      "age_46_55",
                      "age_56_60",
                      "age_over60"
                    ],
                    "description": "Applicant age bracket at time of SAFEA work permit filing."
                  },
                  "chinese": {
                    "type": "string",
                    "enum": [
                      "hsk_5_6",
                      "hsk_4",
                      "hsk_3",
                      "hsk_2",
                      "hsk_1",
                      "hsk_none"
                    ],
                    "description": "Current HSK Mandarin proficiency test level held by applicant (Max 5 pts)."
                  },
                  "location": {
                    "type": "string",
                    "enum": [
                      "loc_western",
                      "loc_standard"
                    ],
                    "description": "Current work orientation regional classification (loc_western=+10, loc_standard=0)."
                  },
                  "localIncentive": {
                    "type": "string",
                    "enum": [
                      "local_10",
                      "local_5",
                      "local_0"
                    ],
                    "description": "Current provincial/municipal encouragement points (local_0, local_5, local_10)."
                  },
                  "bonus": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "bonus_top100_uni",
                        "bonus_fortune500_exp",
                        "bonus_patent_ip",
                        "bonus_china_5yrs"
                      ]
                    },
                    "description": "Already claimed Dimension 8 items (capped at 5 pts total, non-stackable)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/simulate_expat_iit_and_tax_refund": {
      "post": {
        "operationId": "simulate_expat_iit_and_tax_refund",
        "summary": "Mainland China Expatriate IIT Tax & March-June Refund Simulator",
        "description": "Compare Option A fapiao-backed tax-exempt fringe benefits extended through 2027-12-31 (MOF/STA Circular [2023] No. 29) against Option B Tax App Special Additional Deductions across 7 statutory income tax brackets.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "monthlySalaryGross": {
                    "type": "number",
                    "description": "Gross monthly salary in RMB before allowances or tax."
                  },
                  "monthlyRentAllowance": {
                    "type": "number",
                    "description": "Monthly housing rent backed by formal fapiao in RMB."
                  },
                  "monthlyHomeLeaveAllowance": {
                    "type": "number",
                    "description": "Amortized monthly home-leave airfare allowance in RMB."
                  },
                  "hasChildrenEducation": {
                    "type": "boolean",
                    "description": "Whether applicant pays eligible international/private school tuition."
                  },
                  "monthlyChildrenTuition": {
                    "type": "number",
                    "description": "Monthly children tuition allowance with invoice in RMB."
                  },
                  "supportElderlyParents": {
                    "type": "boolean",
                    "description": "Supports parents aged 60+ under Tax App SAD rules."
                  },
                  "monthsWorkedInYear": {
                    "type": "number",
                    "description": "Number of tax-resident months worked during the calendar year (1-12)."
                  }
                },
                "required": [
                  "monthlySalaryGross"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/calculate_job_transfer_runway_deadlines": {
      "post": {
        "operationId": "calculate_job_transfer_runway_deadlines",
        "summary": "In-China Work Permit Transfer & 30-Day Stay Permit Runway Calculator",
        "description": "Compute dual statutory timelines from a resignation date: 30-day advance notice (Labor Contract Law Art. 37), 10-working-day SAFEA Work Permit cancellation deadline (SAFEA Service Guide), 15-calendar-day social security/archive transfer deadline (Labor Contract Law Art. 50), Day+20 transfer cutoff, and 30-day T-Visa hard expiry.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "resignationDate": {
                    "type": "string",
                    "description": "Last working day or official resignation date in YYYY-MM-DD format."
                  },
                  "employerWithholdingRelease": {
                    "type": "boolean",
                    "description": "Include labor arbitration & unilateral SAFEA administrative cancellation SOP when former employer withholds papers."
                  }
                },
                "required": [
                  "resignationDate"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/verify_country_apostille_and_legalization": {
      "post": {
        "operationId": "verify_country_apostille_and_legalization",
        "summary": "China Hague Apostille vs Consular Legalization Country Registry",
        "description": "Look up document authentication requirements across 21 curated issuing jurisdictions to distinguish single-step domestic Hague Apostille from dual-step Chinese Embassy consular legalization, competent bureaus, and turnaround weeks.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "countryQuery": {
                    "type": "string",
                    "description": "ISO 2-letter code (e.g., US, GB, CA, AU, DE, SG, TH, VN, AE) or country name; pass \"all\" to list all 21 countries."
                  },
                  "includeTranslationRules": {
                    "type": "boolean",
                    "description": "Append domestic certified translation seal and 6-month police certificate expiry notes."
                  }
                },
                "required": [
                  "countryQuery"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/compare_municipal_work_permit_policies": {
      "post": {
        "operationId": "compare_municipal_work_permit_policies",
        "summary": "Chinese City Foreigner Work Permit Turnaround & Local Policy Comparator",
        "description": "Inspect and compare municipal processing speeds, Greater Bay Area or Hainan FTP 15% income tax rebates, Category B age-65 exceptions, and designated Travel Healthcare Center locations across 7 Chinese hubs.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "cityId": {
                    "type": "string",
                    "enum": [
                      "shanghai",
                      "beijing",
                      "shenzhen",
                      "guangzhou",
                      "hangzhou",
                      "chengdu",
                      "hainan",
                      "all"
                    ],
                    "description": "Primary Chinese municipality or special economic zone to inspect."
                  },
                  "compareWithCityId": {
                    "type": "string",
                    "enum": [
                      "shanghai",
                      "beijing",
                      "shenzhen",
                      "guangzhou",
                      "hangzhou",
                      "chengdu",
                      "hainan"
                    ],
                    "description": "Optional second city to benchmark turnaround days and tax incentives side by side."
                  },
                  "applicantAge": {
                    "type": "number",
                    "description": "Optional age check against national Category B cap (60) vs Hainan FTP relaxed ceiling (65)."
                  }
                },
                "required": [
                  "cityId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/evaluate_fast_track_and_no_degree_pathways": {
      "post": {
        "operationId": "evaluate_fast_track_and_no_degree_pathways",
        "summary": "SAFEA Direct Category A/B Fast-Track & Non-Degree Legal Waiver Evaluator",
        "description": "Check statutory fast-track exemptions (active Feb 2026 Shanghai ¥895,248/yr & Beijing ¥859,464/yr 6× local average salary thresholds, dynamic municipal formulas, Top-100 postdoc, Fortune 500 executive, Top-100/Chinese Master recent graduate) to see if bachelor degree or 2-year experience rules are waived.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "annualSalaryRmb": {
                    "type": "number",
                    "description": "Offered annual pre-tax RMB compensation for checking automatic 6x Category A exemption."
                  },
                  "targetCity": {
                    "type": "string",
                    "enum": [
                      "shanghai",
                      "beijing",
                      "shenzhen_guangzhou",
                      "tier2_hub",
                      "tier3_western"
                    ],
                    "description": "City wage benchmark group used for 6x local social average salary threshold."
                  },
                  "hasBachelorDegree": {
                    "type": "boolean",
                    "description": "Whether applicant holds an authenticated 4-year university degree."
                  },
                  "yearsExperience": {
                    "type": "number",
                    "description": "Post-graduation full-time experience years."
                  },
                  "categoryFilter": {
                    "type": "string",
                    "enum": [
                      "A",
                      "B",
                      "all"
                    ],
                    "description": "Filter statutory fast-track clauses by Category A, Category B, or all."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    },
    "/api/v1/tools/generate_visa_execution_roadmap_and_arrival_kit": {
      "post": {
        "operationId": "generate_visa_execution_roadmap_and_arrival_kit",
        "summary": "China Z-Visa Transition Sequence, Survival Protocol & Statutory Guide Index",
        "description": "Retrieve end-to-end procedural checklists for overseas Z-visa onboarding, in-country employer changes, X1/S1 status switches, 24h police accommodation rules, and authoritative policy guide briefings.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "scenarioId": {
                    "type": "string",
                    "enum": [
                      "overseas_new",
                      "inchina_transfer",
                      "inchina_status_change"
                    ],
                    "description": "Employment visa transition pathway."
                  },
                  "includeArrivalSurvivalKit": {
                    "type": "boolean",
                    "description": "Include Alipay/WeChat ¥200 rule, 24-hour PSB registration, ITHC medical check, SIM card, and UnionPay banking steps."
                  },
                  "guideSlug": {
                    "type": "string",
                    "enum": [
                      "work-visa-without-degree",
                      "how-to-reach-60-points",
                      "tier-a-b-c-explained",
                      "apostille-authentication-guide",
                      "work-permit-transfer-process",
                      "english-teacher-visa-china"
                    ],
                    "description": "Optional deep-dive guide slug to attach statutory TL;DR and FAQ summary."
                  }
                },
                "required": [
                  "scenarioId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance calculation result"
          }
        }
      }
    }
  }
}
