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

# Load a Model & Detect an Object

POST https://api.amniscient.com/inference/detect-with-model/{model_id}
Content-Type: multipart/form-data

Initializes a model for inference and detects an object within an uploaded image file within a single API call. This eliminates the need to load a model before running detection.

Reference: https://docs.amniscient.com/api/api-reference/detect-with-model

## Request

### Path parameters

- `model_id` (string, required) — The model ID of an active and trained AI model within your organization.

### Headers

- `x-api-key` (string, required) — Your organization's active API Key.

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `organization_id` (string, required) — Your organization's unique identifier.
- `file` (file, required) — An image file you'd like to run detection on.

## Response

### 200

200 - Detection successful

- `xywh` (list of DetectionResponseXywhItems, optional) — An array of information related to the object detected. If an object was not detected, this array will be empty.
- `detection_found` (boolean, optional) — A boolean value denoting whether an object was successfully detected in the image file provided.
- `inference_id` (string, optional) — A unique identifier for the results of a successful inference call.

## Errors

### 400 Bad Request Error

Bad Request

- `detail` (string, optional) — A message describing the successful action or error state.

### 404 Not Found Error

Model Not Found

- `detail` (string, optional) — A message describing the successful action or error state.

## Types

### DetectionResponseXywhItems

- `id` (string, optional) — The detection item id of the object detected. This will match the detection item id in the library for this object.
- `confidence` (double, optional) — A value between 0 and 1 rating how confident the object detection output is based on the model and image provided.
- `x` (double, optional) — A value between 0 and 1 denoting the x coordinate of the detected object.
- `y` (double, optional) — A value between 0 and 1 denoting the y coordinate of the detected object.
- `width` (double, optional) — A value between 0 and 1 describing the width of the detected object.
- `height` (double, optional) — A value between 0 and 1 describing the height of the detected object.
- `tag` (map from string to string, optional) — A map of attributes associated with the detected object. These attributes will match the attributes within the library for this object.

## Examples

**Request**

```json
{
  "file": "<file: string>",
  "organization_id": "string"
}
```

**Response**

```json
{
  "xywh": [
    {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "confidence": 0.95,
      "x": 0.5,
      "y": 0.7,
      "width": 0.4,
      "height": 0.5,
      "tag": {
        "tag_key": "tag_value"
      }
    }
  ],
  "detection_found": true,
  "inference_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

**SDK Code**

```python Successful Detection
import requests

url = "https://api.amniscient.com/inference/detect-with-model/model_id"

files = { "file": "open('string', 'rb')" }
payload = { "organization_id": "string" }
headers = {"x-api-key": "x-api-key"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript Successful Detection
const url = 'https://api.amniscient.com/inference/detect-with-model/model_id';
const form = new FormData();
form.append('file', 'string');
form.append('organization_id', 'string');

const options = {method: 'POST', headers: {'x-api-key': 'x-api-key'}};

options.body = form;

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

```go Successful Detection
package main

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

func main() {

	url := "https://api.amniscient.com/inference/detect-with-model/model_id"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"organization_id\"\r\n\r\nstring\r\n-----011000010111000001101001--\r\n")

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

	req.Header.Add("x-api-key", "x-api-key")

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

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

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

}
```

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

url = URI("https://api.amniscient.com/inference/detect-with-model/model_id")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = 'x-api-key'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"organization_id\"\r\n\r\nstring\r\n-----011000010111000001101001--\r\n"

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

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

HttpResponse<String> response = Unirest.post("https://api.amniscient.com/inference/detect-with-model/model_id")
  .header("x-api-key", "x-api-key")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"organization_id\"\r\n\r\nstring\r\n-----011000010111000001101001--\r\n")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.amniscient.com/inference/detect-with-model/model_id', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ],
    [
        'name' => 'organization_id',
        'contents' => 'string'
    ]
  ]
  'headers' => [
    'x-api-key' => 'x-api-key',
  ],
]);

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

```csharp Successful Detection
using RestSharp;

var client = new RestClient("https://api.amniscient.com/inference/detect-with-model/model_id");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "x-api-key");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"organization_id\"\r\n\r\nstring\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Successful Detection
import Foundation

let headers = ["x-api-key": "x-api-key"]
let parameters = [
  [
    "name": "file",
    "fileName": "string"
  ],
  [
    "name": "organization_id",
    "value": "string"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.amniscient.com/inference/detect-with-model/model_id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```