> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.cargovision.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.cargovision.app/_mcp/server.

# Real-time illegal goods detection via WebSocket stream

POST https://api.cargovision.app/v1/containers/{id}/scans/illegal/stream
Content-Type: image/*

Accepts a single X-ray image frame for a specific container and uses a WebSocket connection on the backend to get real-time illegal goods detections from the AI service.

Reference: https://docs.cargovision.app/api-reference/cargovision-rest-api/containers/real-time-illegal-goods-detection-via-web-socket-stream

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.cargovision.app` (Production Server, default)
- `http://localhost:8080` (Local Development Server)

## Request

### Path parameters

- `id` (string, required)

### Body (image/*)

This endpoint expects binary data of type image/*.

- Binary request body.

## Response

### 200

Real-time illegal goods detection completed.

## Errors

### 400 Bad Request Error

Invalid image format.

- `any`

### 404 Not Found Error

Container not found.

- `any`

### 500 Internal Server Error

Streaming illegal goods scan failed.

- `any`

## Examples

**Response**

```json
{}
```

**SDK Code**

```python
import requests

url = "https://api.cargovision.app/v1/containers/id/scans/illegal/stream"

headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "image/*"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.cargovision.app/v1/containers/id/scans/illegal/stream';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'image/*'}
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.cargovision.app/v1/containers/id/scans/illegal/stream"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "image/*")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.cargovision.app/v1/containers/id/scans/illegal/stream")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'image/*'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.cargovision.app/v1/containers/id/scans/illegal/stream")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "image/*")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.cargovision.app/v1/containers/id/scans/illegal/stream', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'image/*',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.cargovision.app/v1/containers/id/scans/illegal/stream");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "image/*");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "image/*"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.cargovision.app/v1/containers/id/scans/illegal/stream")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```