# Japan Customs HS Code & Duty Calculator (`aulvem/japan-hs-code-duty-calculator`) Actor

Classify products into Japan customs HS9 codes, compute duty + 消費税 (JCT, 10%), and produce JCT-inclusive landed cost in JPY. Built for cross-border merchants pricing into Japan. BYO Anthropic key for LLM classification (publisher charges $0 for LLM calls).

- **URL**: https://apify.com/aulvem/japan-hs-code-duty-calculator.md
- **Developed by:** [Aulvem](https://apify.com/aulvem) (community)
- **Categories:** Business, E-commerce
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Japan Customs HS Code & Duty Calculator

Classify products into Japan customs HS9 codes, compute the applicable duty rate, and produce a JCT-inclusive landed cost — for cross-border e-commerce merchants who need to quote total cost before shipping into Japan.

For each row, you get HS6 candidates with confidence scores, the selected HS9 code, the tariff rate per the appropriate trade agreement, the duty in JPY, the JCT (consumption tax) in JPY, and the total landed cost.

Built for Japan-bound merchants on Shopify, BASE, Stores, custom storefronts, and for the 通関業者 / 輸入代行 / 越境 EC コンサル who price their service against actual customs cost.

### What it computes

For each item in a single Apify run:

- **HS6 classification**: Top 3 candidates with confidence scores (when LLM mode is on)
- **HS9 resolution**: First HS9 child of the highest-confidence HS6, or the user-supplied `knownHs9` if provided
- **Tariff rate**: Per-HS9 rate at MFN or agreement-based (EPA / GSP / ITA), derived from the bundled snapshot of 税関 公表データ
- **Duty in JPY**: `floor(CIF × rate%)`
- **JCT**: `floor((CIF + duty) × 10%)` — standard 消費税 rate
- **Total landed JPY**: `CIF + duty + JCT` — what your customer effectively pays in import cost

### When to use it

- **Pre-quote calculator**: Before listing a product for sale into Japan, run it through to know the customer's total landed cost — useful for accurate ¥ pricing in Shopify
- **Bulk reclassification**: When 国税庁 or 税関 publish a tariff schedule update, batch-re-validate your SKU catalog
- **Onboarding 通関業者**: Send your customs broker an Apify dataset URL instead of an Excel sheet; they can re-run as your catalog updates
- **CI / nightly check**: Schedule the Actor nightly via Apify Scheduler to recompute landed cost for new SKUs

### Two modes

| Mode | When | Cost |
|---|---|---|
| **`knownHs9` path** | You already know the 9-digit HS code | $0.001/row, no LLM API call |
| **LLM classifier** | You only have a product description | $0.001/row Apify PPE **+ ~$0.020/row Anthropic API** charged to YOUR Anthropic key (BYO key, see Input tab) |

The Actor publisher does NOT charge you for the LLM call. You bring your own Anthropic key from [console.anthropic.com](https://console.anthropic.com) and the call is made directly from the Actor to Anthropic with your credential. The Actor never logs the key.

### Input

```json
{
  "items": [
    {
      "ref": "sku-001",
      "description": "Cotton T-shirt with printed graphic",
      "originCountry": "VN",
      "cifJpy": 50000,
      "language": "en"
    }
  ],
  "useLlmClassifier": true,
  "anthropicApiKey": "sk-ant-..."
}
````

Field reference is in the **Input** tab. For pure landed-cost computation with no classification, supply `knownHs9` per item and leave `useLlmClassifier: false`.

### Output

One dataset row per item:

| Field | Type | Description |
|---|---|---|
| `ref` | string | null | Echoed back for matching |
| `description` | string | Echo of input |
| `originCountry` | string | Echo of input |
| `candidates` | array | HS6 candidates from classifier (or single knownHs9 entry) |
| `selectedHs9` | string | null | The 9-digit code used for duty computation |
| `tariffRatePct` | number | null | Rate applied (e.g. 7.4 for 7.4%) |
| `tariffKind` | string | null | "agreement-or-default" or null |
| `duty` | integer | JPY |
| `jct` | integer | JPY |
| `totalLandedJpy` | integer | CIF + duty + JCT |
| `warnings` | string\[] | Issues: missing knownHs9, LLM failure, unknown rate |

### Pricing

- **Pay-Per-Result (PPE)**: $0.001 per item processed (Apify charge)
- **LLM mode add-on**: ~$0.020/row on your own Anthropic billing (Actor publisher receives $0)
- **Free tier**: First 5 runs/day per Apify account

For a 1,000-SKU catalog with all `knownHs9` (no LLM), total = $1.00. Same catalog with full LLM classification: $1.00 Apify + ~$20 on your Anthropic key.

### Legal context & limitations

- HS code data snapshot is the bundled `@ws/jp-hs-code` 2026 version (heading-level mapping). For specific HS9 codes outside the snapshot, the Actor emits a warning and falls back to 0% duty (you must verify against [税関 tariff search](https://www.customs.go.jp)).
- This Actor surfaces classification mechanically; **it does not replace a 通関士 or 通関業者**. Final classification disposition is your broker's call, especially for borderline cases (cosmetics vs medicaments, knit vs woven apparel, electronics chapter 85 vs 90).
- JCT computation uses the standard 10% rate. Reduced rate (8%) for some food / 新聞 items is not implemented.

### Roadmap

- v0.2: Per-HS9 tariff rate snapshot from customs.go.jp (replace heading-level placeholder)
- v0.3: Auto-classifier fine-tune feedback loop (customer corrections → improved confidence)
- v0.4: Shopify Admin API connector (skip JSON marshaling for Shopify-Japan stores)

Maintained by **aulvem**. Bug reports / feature requests via the **Issues** tab on the Actor page.

***

### Developer notes

This Actor is part of a [shared-modules monorepo](https://aulvem.pages.dev). Classifier logic lives in `apps/apify-jp-hs-code/src/classifier.ts` (16 unit tests). Tariff snapshot in `@ws/jp-hs-code` (12 unit tests).

The Anthropic API key is read EXCLUSIVELY from `input.anthropicApiKey` — never from `process.env`. This guarantees that LLM cost lands on the Apify customer, not on the Actor publisher's Anthropic account (BYO-key policy).

Local run (developers only):

```powershell
cd apps/apify-jp-hs-code
pnpm tsx src/main.ts
```

Uses Apify SDK in local mode; expects an `INPUT.json` in the configured KV store. See [Apify SDK local development docs](https://docs.apify.com/sdk/js/docs/guides/local-development).

Deploy is via the bundle pipeline:

```powershell
./scripts/apify-build-bundle.sh @apps/apify-jp-hs-code japan-hs-code-duty-calculator apps/apify-jp-hs-code
cd apify-deploy/japan-hs-code-duty-calculator
pnpm dlx apify-cli push --force
```

Pre-push sanity checks live in [docs/apify-actor-sanity-check.md](../../docs/apify-actor-sanity-check.md).

# Actor input Schema

## `items` (type: `array`):

One row per product to classify. The classifier reads the description in English (preferred) or Japanese.

## `useLlmClassifier` (type: `boolean`):

When true, runs the description through Claude Sonnet for HS6 classification. Requires anthropicApiKey below. Items with knownHs9 skip the classifier regardless. The Anthropic charge (~$0.020/classified row) goes to YOUR key, not the Actor publisher.

## `anthropicApiKey` (type: `string`):

Bring your own key from console.anthropic.com. The Actor never stores or logs this value, and the cost of LLM calls (~$0.020 per classified row) goes to YOUR Anthropic account, not the Actor publisher's. Leave blank if you only use the knownHs9 path.

## Actor input object example

```json
{
  "useLlmClassifier": false
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("aulvem/japan-hs-code-duty-calculator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("aulvem/japan-hs-code-duty-calculator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call aulvem/japan-hs-code-duty-calculator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=aulvem/japan-hs-code-duty-calculator",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Japan Customs HS Code & Duty Calculator",
        "description": "Classify products into Japan customs HS9 codes, compute duty + 消費税 (JCT, 10%), and produce JCT-inclusive landed cost in JPY. Built for cross-border merchants pricing into Japan. BYO Anthropic key for LLM classification (publisher charges $0 for LLM calls).",
        "version": "0.1",
        "x-build-id": "b5GhnWq1MDAFhfFTw"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/aulvem~japan-hs-code-duty-calculator/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-aulvem-japan-hs-code-duty-calculator",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/aulvem~japan-hs-code-duty-calculator/runs": {
            "post": {
                "operationId": "runs-sync-aulvem-japan-hs-code-duty-calculator",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/aulvem~japan-hs-code-duty-calculator/run-sync": {
            "post": {
                "operationId": "run-sync-aulvem-japan-hs-code-duty-calculator",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "items"
                ],
                "properties": {
                    "items": {
                        "title": "Items to classify",
                        "minItems": 1,
                        "type": "array",
                        "description": "One row per product to classify. The classifier reads the description in English (preferred) or Japanese.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "ref": {
                                    "title": "External reference",
                                    "type": "string",
                                    "description": "Passed through unchanged in the output for matching (e.g. SKU, line item ID)."
                                },
                                "description": {
                                    "title": "Product description (EN or JA)",
                                    "type": "string",
                                    "minLength": 5,
                                    "maxLength": 500,
                                    "description": "Free-text product description, English preferred. Used by the LLM classifier when knownHs9 is not supplied."
                                },
                                "originCountry": {
                                    "title": "Origin country (ISO 3166-1 alpha-2)",
                                    "type": "string",
                                    "minLength": 2,
                                    "maxLength": 2,
                                    "description": "Manufacturer country code, e.g. VN, CN, US. Affects which tariff agreement rate applies."
                                },
                                "cifJpy": {
                                    "title": "CIF value (JPY)",
                                    "type": "integer",
                                    "minimum": 0,
                                    "description": "Cost + Insurance + Freight in JPY. Used as the duty/JCT base."
                                },
                                "language": {
                                    "title": "Description language hint",
                                    "type": "string",
                                    "enum": [
                                        "en",
                                        "ja"
                                    ],
                                    "description": "Hint to the LLM classifier. Defaults to en when omitted."
                                },
                                "knownHs9": {
                                    "title": "Known 9-digit HS code (optional)",
                                    "type": "string",
                                    "pattern": "^\\d{9}$",
                                    "description": "If the merchant already knows the 9-digit code, supply it to skip the LLM classifier (and save ~$0.020/row in Anthropic charges)."
                                }
                            },
                            "required": [
                                "description",
                                "originCountry",
                                "cifJpy"
                            ]
                        }
                    },
                    "useLlmClassifier": {
                        "title": "Use the Claude LLM classifier",
                        "type": "boolean",
                        "description": "When true, runs the description through Claude Sonnet for HS6 classification. Requires anthropicApiKey below. Items with knownHs9 skip the classifier regardless. The Anthropic charge (~$0.020/classified row) goes to YOUR key, not the Actor publisher.",
                        "default": false
                    },
                    "anthropicApiKey": {
                        "title": "Anthropic API key (required when useLlmClassifier is true)",
                        "type": "string",
                        "description": "Bring your own key from console.anthropic.com. The Actor never stores or logs this value, and the cost of LLM calls (~$0.020 per classified row) goes to YOUR Anthropic account, not the Actor publisher's. Leave blank if you only use the knownHs9 path."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
