문서/Anyuse API 빠른 시작
Anyuse API 빠른 시작
샤오홍슈에서 ‘커피’를 검색해 봅니다. 견적 조회는 무료이며, 실행을 승인하면 계정 잔액에서 실제 비용이 차감됩니다. 아래 예제는 터미널에서 Bash, curl, jq, uuidgen으로 실행하세요. 각 견적의 파일을 보관할 빈 디렉터리에서 시작하세요.
1. API 키 준비
콘솔의 API 키에서 실행 키를 만드세요. 키를 환경 변수 ANYUSE_API_KEY에 저장하고 실행 전에 잔액을 확인하세요.
Bash
read -rs -p 'Anyuse API 키: ' ANYUSE_API_KEY
export ANYUSE_API_KEY
echo2. 무료 견적 받기
cURL
curl --fail-with-body -sS https://api.anyuse.app/v1/quotes \
-H "Authorization: Bearer $ANYUSE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"operation":"redbook.note.search","input":{"keyword":"커피","page":1}}' \
-o quote.json
jq '{id, price_usd, requires_budget, expires_at}' quote.jsonprice_usd와 만료 시각을 확인하세요. 아래 명령은 requires_budget이 false인 고정 가격 견적에 사용합니다. true이면 실행 전에 별도로 최대 예산을 정해야 합니다.
3. 금액 확인 후 실행
승인한 견적의 실행 요청과 멱등 키를 한 번만 준비하세요. 응답을 받지 못하면 두 파일을 그대로 사용해 같은 실행을 복구할 수 있습니다.
요청 준비
jq -e 'select(.requires_budget == false and .id != null and .price_usd != null) | {quote_id: .id, max_cost_usd: .price_usd}' quote.json > request.json && uuidgen > request.key실행
curl --fail-with-body -sS 'https://api.anyuse.app/v1/executions?wait_ms=10000' \
-H "Authorization: Bearer $ANYUSE_API_KEY" \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $(cat request.key)" \
--data-binary @request.json -o execution.json
jq '{id, status, cost_usd, error_code}' execution.json4. 결과 읽기
실행 중이면 같은 ID로 상태를 다시 조회하세요. succeeded가 되면 result.data.items에서 게시물 목록을, cost_usd에서 실제 비용을 확인할 수 있습니다.
결과 조회
curl --fail-with-body -sS "https://api.anyuse.app/v1/executions/$(jq -er .id execution.json)" \
-H "Authorization: Bearer $ANYUSE_API_KEY" | jq '{status, cost_usd, items: .result.data.items}'게시물 검색의 매개변수와 응답 필드에서 필터와 페이지 이동 방법을 확인하세요. 다른 작업을 호출하려면 전체 API 문서에서 해당 요청 예제를 선택하세요.