iOS quickstart
Everything an iOS app needs to check a message with DefAI. Every example on this page is replayed against the API by the test suite, and against the production server before this page is shared.
| Base URL | https://defai.austriaeast.cloudapp.azure.com |
| API spec (stable) | /openapi/v1.json — pin to this; it only changes on purpose |
| Full reference | API reference |
| Sample JSON | /guide/api/samples/<name>.json — listed under Samples for previews |
| Postman collection | Import → Link: https://defai.austriaeast.cloudapp.azure.com/postman.json — see Postman |
HTTPS only. The certificate is a normal Let's Encrypt one, so no App Transport Security exception is needed.
Postman
In Postman choose Import → Link and paste:
https://defai.austriaeast.cloudapp.azure.com/postman.json
That link always serves the collection for the API that is live now: it is rebuilt with every deploy. Postman keeps its own copy, so after an API change import the link again and choose Replace. Or download the file and use Import → File.
Every request on this page is in it, with the real response saved as an example. The base URL is the baseUrl collection variable. Run collection checks each response against what this page promises. The feedback request queues a real review item, so leave it out of repeated runs.
Authentication
None. Scanning, batch scanning, feedback, capabilities and health are open to any client and protected by a rate limit, not a key.
- Never put an
X-API-Keyin the app. Keys exist only for the staff review endpoints (/v1/review/...), and anything shipped in an app can be extracted. With ScamGuardKit, passapiKey: nil. GET /v1/capabilitiesreturns"auth_required": trueon production. That flag describes the staff endpoints, not scanning. Ignore it in the app.
Scan a message
POST /v1/analyze/message
curl -s https://defai.austriaeast.cloudapp.azure.com/v1/analyze/message \
-H 'Content-Type: application/json' \
-d '{"text": "Emirates NBD: Your account is suspended. Share the OTP sent to your phone and verify at http://enbd-secure-verify.top/login to avoid closure.",
"source_type": "sms", "source_app": "ios", "sender": "ENBD-Alert", "locale": "en-AE"}'
| Field | Required | Notes |
|---|---|---|
text | yes | 1 to 20,000 characters |
source_type | yes | sms · email · chat · call_transcript · social · other |
source_app | yes | Use ios |
sender | no | Phone number or SMS sender name, e.g. ENBD-Alert |
locale | recommended | Always send the device locale, with a hyphen: en-AE, ar-AE. Without it, Arabic messages that contain a link can come back with limited coverage and a warning note |
user_consent_online_checks | no | false by default. Set true only after the user agrees in the app: it lets the server send domains and numbers to third-party services |
Response (200), shortened. Full file: scan-scam.json
{
"analysis_id": "602e757d-6a99-47d7-8740-6670046c875d",
"risk_score": 1.0,
"risk_level": "scam",
"category": "otp_phishing",
"explanation": "Matched 2 scam pattern(s): Claims your bank account/card will be blocked or suspended; Asks you to share an OTP/verification code — legitimate services never do | Suspicious link(s): enbd-secure-verify.top (high-abuse TLD .top, brand name combined with hyphens/phishing keywords (lookalike domain)) | …",
"recommended_action": "This is almost certainly a scam. Do not respond. Block the sender and report it to your bank/authorities if you shared anything.",
"detected_language": "en",
"coverage": "full",
"coverage_note": null,
"review_status": "auto",
"matched_rules": [
{"id": "bank-account-suspension", "category": "bank_impersonation",
"description": "Claims your bank account/card will be blocked or suspended", "weight": 0.55}
],
"urls": [
{"url": "http://enbd-secure-verify.top/login", "domain": "enbd-secure-verify.top", "suspicious": true,
"reasons": ["high-abuse TLD .top", "brand name combined with hyphens/phishing keywords (lookalike domain)"],
"score": 0.85, "listed_by": []}
],
"processing": {"local_stages": ["redaction", "rule engine", "URL heuristics", "identity checks (local registry)"],
"external_stages": [], "external_consented": false, "notes": []}
}
The same scam in Arabic: scan-scam-ar.json. Several messages at once: POST /v1/analyze/batch with {"messages": [...]}, up to 50 items — batch.json. If any item is invalid (empty, over 20,000 characters, unknown source_type), the whole batch is rejected with 422, so check each message on the device before sending. An item that fails inside the server comes back with its own error while the rest succeed.
What a verdict means
risk_level | Show the user |
|---|---|
scam | Almost certainly a scam. Lead with recommended_action. |
likely_scam | Probably a scam. Same treatment. |
suspicious | Not sure. Show the reasons and tell them to verify through the official app or number. |
safe | No warning signs found. Never word it as "this is safe" — see coverage below. |
risk_scoreis a risk index from 0 to 1, not a probability. Don't show it as a percentage chance.coveragesays whether the checks could read the language:full,limitedornone. When it isn'tfull, a low score is not evidence of safety. Showcoverage_noteprominently.explanationandmatched_rules[].descriptionare the reasons, in plain English.urls[]explains each link.urls[].listed_bynames the link lists (PhishTank, URLhaus) that list this link (match: "url") or its whole site ("host"), withlist_updated_at. Show the source and its age. An empty list is not evidence the link is safe.review_statusneeds_reviewmeans a person will look at this verdict. Nothing for the app to do.processinglists what ran on the server and what was sent to third parties (external_stages). Show it if your privacy screen explains checks.
Uncertain results
Suspicious — scan-suspicious.json: a delivery notice behind a link shortener gets risk_level suspicious, risk_score 0.4, review_status needs_review.
A language the checks can't read — scan-limited-coverage.json:
{
"risk_score": 0.0,
"risk_level": "safe",
"detected_language": "fr",
"coverage": "none",
"coverage_note": "No detection coverage for French. This message was NOT analyzed — the absence of warnings does not mean it is safe."
}
risk_level says safe only because nothing could be matched. The app must show coverage_note, not a green tick.
Errors
422 and 429 bodies are JSON with a detail field. 500, 502 and 503 bodies are not JSON: a 500 is plain text, and a 502 or 503 from the proxy is empty. Decode detail optionally and fall back to the status code.
| Status | Meaning | What the app does |
|---|---|---|
| 422 | The request is invalid (field missing, text too long). detail is a list of problems. error-validation.json | Fix the request. Don't retry. |
| 429 | Too many requests from this IP: 120 per 60 seconds. detail: "rate limit exceeded, slow down". error-rate-limit.json | Retry with exponential backoff (2 s, 4 s, 8 s …, up to 60 s). |
| 500 | A bug on the server. Plain-text body. | Don't retry automatically. Say "Couldn't check this message". |
| 502, 503 | The server is restarting, usually for a few seconds during a deploy. Empty body. | Retry after 2 s, up to 3 times. |
| Timeout | No answer in time. | Retry once, then say "Couldn't check this message". |
429 on mobile data is normal. Many phones share one public IP on a carrier network, so they share one limit. Retry quietly; don't show an error on the first 429.
A failed check is never a "safe" result. If the app can't get a verdict, say so.
Limits and timeouts
| Message length | 20,000 characters |
| Batch size | 50 messages |
| Rate limit | 120 requests per 60 seconds, per IP address |
| Request timeout | 10 s for a scan; 20 s when user_consent_online_checks is true |
Scans normally answer in well under a second, plus network time. Feature-detect with GET /v1/capabilities (capabilities.json) on launch; GET /v1/health (health.json) is a liveness check.
Check a link with VirusTotal
When GET /v1/capabilities has features.virustotal_check: true, you can offer a "Check this link with VirusTotal" button under a link. It sends the link to VirusTotal, a Google service, so ask the user first, then call POST /v1/links/virustotal with {"url": …, "consent": true}. Without consent the server answers 400 and sends nothing: virustotal-without-consent.json. Show message as is (it never says a link is safe) and link report_url. status: "queued" means VirusTotal is scanning it now; ask again in a minute. Timeout: 20 s. See the API reference.
"This looks wrong"
POST /v1/feedback with the analysis_id from the result and what the user expected (scam, legitimate or unsure) — feedback.json. It queues the verdict for a person to review. It doesn't change the result.
Privacy
- Message text is never stored. The checks read the message in memory. Phone numbers, card numbers, codes, emails, IBANs and similar are removed before anything is stored or passed to an AI model. The server keeps only metadata: scores, matched rule IDs, link domains and keyed fingerprints.
- The one exception is feedback: if the user explicitly agrees to include the message (
shared_textwithshare_consent: trueon/v1/feedback), a redacted copy is kept for a person to review. - Nothing is sent to third parties unless the user opts in with
user_consent_online_checks. Ask them in the app first, and say what it does: domains and phone numbers may be looked up with outside services.processing.external_stagesshows what was actually sent. - The server's request log keeps IP addresses for 14 days.
Swift
The repo's ScamGuardKit has a ready-made client (the repo is private, so ask for access). It uses URLSession's default 60 s timeout and has no 429 backoff, so add the timeouts and retries above yourself:
import Foundation
func scanWithKit() async {
// ScamGuardAPI ships in clients/ios/ScamGuardKit. Never pass a real key.
// let api = ScamGuardAPI(baseURL: URL(string: "https://defai.austriaeast.cloudapp.azure.com")!, apiKey: nil)
// let result = try await api.analyze(text: messageText, sourceType: "sms")
}
Without the kit, here's a complete minimal client:
import Foundation
struct ScanRequest: Encodable {
let text: String
let source_type: String
let source_app = "ios"
var sender: String? = nil
// Always send it. The server expects "ar-AE", iOS gives "ar_AE".
var locale: String? = Locale.current.identifier.replacingOccurrences(of: "_", with: "-")
var user_consent_online_checks = false
}
struct ScanResult: Decodable {
let analysis_id: String
let risk_score: Double // a risk index, not a probability
let risk_level: String // safe | suspicious | likely_scam | scam
let explanation: String
let recommended_action: String
let coverage: String // full | limited | none
let coverage_note: String?
}
enum ScanError: Error {
case rateLimited // 429: retry with backoff
case invalidRequest(String?) // 422: fix the request
case unavailable(Int) // 500, 502, 503: "Couldn't check this message"
}
private struct ErrorBody: Decodable { let detail: String? }
func scan(_ text: String, sender: String? = nil) async throws -> ScanResult {
var request = URLRequest(url: URL(string: "https://defai.austriaeast.cloudapp.azure.com/v1/analyze/message")!)
request.httpMethod = "POST"
request.timeoutInterval = 10 // 20 when user_consent_online_checks is true
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONEncoder().encode(ScanRequest(text: text, source_type: "sms", sender: sender))
let (data, response) = try await URLSession.shared.data(for: request)
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0
switch statusCode {
case 200:
return try JSONDecoder().decode(ScanResult.self, from: data)
case 429:
throw ScanError.rateLimited
case 422:
// 422's detail is a list, so this yields nil; log `data` while developing.
throw ScanError.invalidRequest(try? JSONDecoder().decode(ErrorBody.self, from: data).detail)
default:
// 502/503 from the proxy have an empty body: never assume JSON here.
throw ScanError.unavailable(statusCode)
}
}
Samples for previews
Each file is {"request": …, "status": …, "response": …}, captured from the real API. Drop them into the app's Preview Content or test bundle:
scan-scam.json · scan-scam-ar.json · scan-suspicious.json · scan-limited-coverage.json · batch.json · feedback.json · capabilities.json · health.json · error-validation.json · error-rate-limit.json
import Foundation
struct Sample<Response: Decodable>: Decodable {
let status: Int
let response: Response
}
/// For #Preview and tests: loadSample("scan-suspicious") gives a real "suspicious" result.
func loadSample(_ name: String, in bundle: Bundle = .main) -> ScanResult {
let url = bundle.url(forResource: name, withExtension: "json")!
let data = try! Data(contentsOf: url)
return try! JSONDecoder().decode(Sample<ScanResult>.self, from: data).response
}