读取商品照片,以 JSON 返回结构化属性。
密钥以 rsw_ 开头,仅在创建时显示一次。请把密钥保存在服务器上,并通过环境变量 RAWSWITCH_API_KEY 提供给代码。
export RAWSWITCH_API_KEY="rsw_live_…"所有模型都响应同一个端点。请求体是统一的外层结构:model 选择模型,input 承载该模型自己的字段,webhook、route 和 tags 为可选。
curl -X POST https://rawswitch.ai/v1/requests \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "rawswitch/product-attributes",
"input": {
"image_url": "https://files.rawswitch.example/samples/jacket-front.jpg",
"schema": "apparel"
}
}'请求被接受并进入队列。你会拿到请求 ID 和用于跟踪状态的 URL。
{
"id": "req_01JDF3K8Q2",
"status": "queued",
"urls": {
"self": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2",
"events": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/events",
"cancel": "https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/cancel"
}
}在 Authorization 请求头中以 Bearer 令牌形式发送密钥。没有有效密钥的调用会以 error.type = "authentication_error" 失败。
Authorization: Bearer $RAWSWITCH_API_KEY请求依次经过 queued → running → succeeded、failed 或 canceled。短任务可以让提交调用等待:它会返回在时限内到达的状态。
curl -X POST "https://rawswitch.ai/v1/requests?wait=60" \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6b1f0c1e-2f0a-4c57-9a55-1d2f6f0b7c11" \
-d @body.jsonIdempotency-Key,重试时使用同一个值。否则重试的请求可能再次运行并重复计费。一次调用即可拿到状态,完成后还会一并返回输出。
curl https://rawswitch.ai/v1/requests/req_01JDF3K8Q2 \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"通过服务器发送事件(SSE)实时跟踪请求,无需反复轮询。
curl -N https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/events \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"
event: status
data: {"status":"running"}
event: status
data: {"status":"succeeded"}served_by 是生成输出的路径名称,attempts 列出所有尝试过的路径。路由过程没有任何隐藏。
{
"id": "req_01JDF3K8Q2",
"model": "rawswitch/product-attributes",
"status": "succeeded",
"output": {
"attributes": {
"category": "jacket",
"colour": "navy",
"material": "cotton twill",
"fit": "regular",
"sleeve": "long",
"closure": "zip",
"pattern": "solid"
},
"confidence": 0.93
},
"served_by": "npu/self-hosted",
"attempts": [
{
"route": "npu/self-hosted",
"status": "succeeded"
}
],
"usage": {
"unit": "image",
"quantity": 1
},
"timings": {
"queued_ms": 38,
"running_ms": 4120
}
}curl -X POST https://rawswitch.ai/v1/requests/req_01JDF3K8Q2/cancel \
-H "Authorization: Bearer $RAWSWITCH_API_KEY"输入接受 URL。公开 URL 可以直接使用。本地文件需先获取上传 URL,把文件发送过去,再传入返回的 file_url。
# 1) ask for an upload URL
curl -X POST https://rawswitch.ai/v1/files \
-H "Authorization: Bearer $RAWSWITCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"filename": "jacket-front.jpg", "content_type": "image/jpeg"}'
# 2) send the bytes to upload_url, then use file_url in your input
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/jpeg" --data-binary @jacket-front.jpg在请求中加入 webhook,Rawswitch 会在请求完成后把结果 POST 到你的 URL。投递按 Standard Webhooks 规范签名,你的端点失败时会重试。
{
"model": "rawswitch/product-attributes",
"input": {},
"webhook": {
"url": "https://your-app.example/hooks/rawswitch"
}
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| image_url | string (URL) | 是 | 要识别的商品照片。上传文件或粘贴 URL。 |
| schema | enum | — | 选择要返回哪些字段。可选值:apparel, footwear, accessories, generic。默认值 "apparel"。 |
| language | enum | — | 自由文本字段使用的语言。可选值:en, ko, ja。默认值 "en"。 |
结果是 JSON,原样放在 output 中,字段如下。
| 字段 | 类型 | 说明 |
|---|---|---|
| attributes | object | 所选属性集的结构化字段。 |
| confidence | number | 0~1。模型对整体识别结果的置信度。 |
{
"attributes": {
"category": "jacket",
"colour": "navy",
"material": "cotton twill",
"fit": "regular",
"sleeve": "long",
"closure": "zip",
"pattern": "solid"
},
"confidence": 0.93
}此模型背后的路径:
npu/self-hosted — 自有 NPU (计划中)粘贴到编程 Agent 中。其中包含端点、Schema,以及安全调用此模型的规则。
You are adding the Rawswitch model `rawswitch/product-attributes` (Product Attributes — image to json) to this codebase.
## What it does
Reads a product photo and returns structured attributes as JSON.
Price: not set yet.
## API
- Base URL: https://rawswitch.ai
- Auth: header `Authorization: Bearer <key>`. Read the key from the `RAWSWITCH_API_KEY` environment variable. Never hard-code it and never send it to the browser.
- Submit: `POST /v1/requests` with JSON `{ model, input, webhook?, route?, tags? }`. The response is `{ id, status: "queued", urls }`.
- Result: `GET /v1/requests/{id}` until `status` is `succeeded`, `failed` or `canceled`. One call returns status and output together.
- Short jobs: `POST /v1/requests?wait=60` waits up to 60 seconds and returns whatever state the request reached.
- Live status: `GET /v1/requests/{id}/events` is a server-sent event stream.
- Cancel: `POST /v1/requests/{id}/cancel`.
- Files: `POST /v1/files` returns `{ upload_url, file_url }`. PUT the bytes to `upload_url`, then pass `file_url` in the input.
## Request
```json
{
"model": "rawswitch/product-attributes",
"input": {
"image_url": "https://files.rawswitch.example/samples/jacket-front.jpg",
"schema": "apparel"
}
}
```
## Input fields
- `image_url` (URL, required): The product photo to read. Upload a file or paste a URL.
- `schema` (string, one of "apparel", "footwear", "accessories", "generic", default "apparel"): Which fields to return.
- `language` (string, one of "en", "ko", "ja", default "en"): Language of free-text fields.
## Output
- `attributes` (object): Structured fields for the chosen attribute set.
- `confidence` (number): 0 to 1. How sure the model is about the whole reading.
```json
{
"attributes": {
"category": "jacket",
"colour": "navy",
"material": "cotton twill",
"fit": "regular",
"sleeve": "long",
"closure": "zip",
"pattern": "solid"
},
"confidence": 0.93
}
```
## Rules to follow
- Send an `Idempotency-Key` header (a UUID per logical job) on every submit, and reuse the same key when you retry. A retry without it can run and bill twice.
- Do not poll faster than once per second. Prefer `?wait=`, the event stream or a webhook over tight polling.
- On `failed`, branch on `error.type`; show `error.message` to the user. Do not switch to another model yourself: Rawswitch already retries the same model on another path, and a different model is a product decision.
- Log `id`, `served_by` and `attempts` with your own request log. They say which path served the call.
- Output file URLs are for download. Copy the files into your own storage if you need to keep them.
- If you receive webhooks, verify the Standard Webhooks signature before trusting the body.
## Paths behind this model
- `npu/self-hosted` — Self-hosted NPU (planned)
Write a small typed function that submits a request, waits for the result and returns the output. Add one test that mocks the HTTP calls.示例中的基础 URL https://rawswitch.ai 是域名确定前的占位值。