> For the complete documentation index, see [llms.txt](/llms.txt).
[◆ miniwebtool /api](/)
[Tools](/tools/) [Docs](/docs/) [Reference](/v1/docs) [Pricing](/#pricing) [Log in](/dashboard/login/) [Start free](/billing/checkout/?plan=free)
- [Home](/)
- ›
- [Tools](/tools/)
- ›
- [Random](/tools/#random)
- ›
- Random Port Number Generator API

# Random Port Number Generator API

random 1 credits / call v2026-04-22
Generate random network port numbers in standard or custom ranges.
Use this endpoint to add Random Port Number Generator to your app, site, workflow, or agent without rebuilding formulas, validation, examples, and docs.
Prefer the browser version? [Open the Random Port Number Generator on miniwebtool.com](https://miniwebtool.com/random-port-number-generator/).
[Start free — get a key →](/billing/checkout/?plan=free) 1,000 credits · no card · 30 seconds
What this saves
Skip a custom implementation, validation rules, examples, OpenAPI shape, billing checks, and support copy for this utility.
Where it fits
Product forms, calculator pages, finance content, education flows, support tools, automations, and agent actions.
How to evaluate
Inspect the required fields, try the hosted playground, then copy cURL, Python, or Node code into your integration.

### Endpoint

```text
POST https://api.miniwebtool.com/v1/tools/random-port-number-generator/run
```

### Request body

Field
Type
Req.
`port_range`
all | well-known | registered | dynamic | custom
`str`
—
`quantity`
`int`
—
`avoid_common`
`bool`
—
`unique_only`
`bool`
—
`custom_min`
`int | None`
—
`custom_max`
`int | None`
—
`seed`
`int | None`
—

### Cost & access

- 1 credit per successful call.
- Starts on: Free.
- Max payload: 65536 bytes.
- Privacy mode:`hash_only`
- Available on: free, starter, pro, business, scale

### Response envelope

```text
{
  "request_id": "01K...",
  "tool": "random-port-number-generator",
  "tool_version": "2026-04-22",
  "credits_used": 1,
  "result": {... }
}
```

### Try it

API key *
Stored only in this browser tab. Playground test key is prefilled and only works on this page. [Get a live key →](/billing/checkout/?plan=free)
port_range (str) all well-known registered dynamic custom
all | well-known | registered | dynamic | custom
quantity (int)
avoid_common (bool) false true
unique_only (bool) false true
custom_min (int | None)
custom_max (int | None)
seed (int | None)
Send request →
Response copy body
This endpoint starts on Free
Your key is valid, but its current plan cannot call`random-port-number-generator`. Upgrade to Free or higher to run this tool.
[Start Free →](/billing/checkout/?plan=free) [Compare plans](/#pricing)

```text

```

Response headers

```text

```

### Code examples

cURL Python JavaScript PHP Ruby Go Java
copy

```text
curl -X POST https://api.miniwebtool.com/v1/tools/random-port-number-generator/run \
  -H 'Authorization: Bearer mwt_live_YOUR_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"port_range":"dynamic","quantity":5,"unique_only":true}'
```

copy

```text
import requests

resp = requests.post(
    'https://api.miniwebtool.com/v1/tools/random-port-number-generator/run',
    headers={'Authorization': 'Bearer mwt_live_YOUR_KEY'},
    json={'port_range': 'dynamic', 'quantity': 5, 'unique_only': True},
)
resp.raise_for_status()
print(resp.json())
```

copy

```text
const resp = await fetch(
  'https://api.miniwebtool.com/v1/tools/random-port-number-generator/run',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer mwt_live_YOUR_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"port_range":"dynamic","quantity":5,"unique_only":true}),
  }
);
const data = await resp.json();
console.log(data);
```

copy

```text
<?php
$ch = curl_init('https://api.miniwebtool.com/v1/tools/random-port-number-generator/run');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer mwt_live_YOUR_KEY',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
    'port_range' => 'dynamic',
    'quantity' => 5,
    'unique_only' => true
]),
]);
$resp = curl_exec($ch);
curl_close($ch);
print_r(json_decode($resp, true));
```

copy

```text
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://api.miniwebtool.com/v1/tools/random-port-number-generator/run')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')

req = Net::HTTP::Post.new(uri)
req['Authorization'] = 'Bearer mwt_live_YOUR_KEY'
req['Content-Type'] = 'application/json'
req.body = {
  'port_range' => 'dynamic',
  'quantity' => 5,
  'unique_only' => true
}.to_json

resp = http.request(req)
puts JSON.parse(resp.body).inspect
```

copy

```text
package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "io"
  "net/http"
)

func main() {
  body, _:= json.Marshal(map[string]interface{}{
    "port_range": "dynamic",
    "quantity": 5,
    "unique_only": true,
  })
  req, _:= http.NewRequest("POST", "https://api.miniwebtool.com/v1/tools/random-port-number-generator/run", bytes.NewReader(body))
  req.Header.Set("Authorization", "Bearer mwt_live_YOUR_KEY")
  req.Header.Set("Content-Type", "application/json")

  resp, err:= http.DefaultClient.Do(req)
  if err!= nil { panic(err) }
  defer resp.Body.Close()
  out, _:= io.ReadAll(resp.Body)
  fmt.Println(string(out))
}
```

copy

```text
import java.net.URI;
import java.net.http.*;

var client = HttpClient.newHttpClient();
var req = HttpRequest.newBuilder()
.uri(URI.create("https://api.miniwebtool.com/v1/tools/random-port-number-generator/run"))
.header("Authorization", "Bearer mwt_live_YOUR_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"port_range\":\"dynamic\",\"quantity\":5,\"unique_only\":true}"))
.build();

var resp = client.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
```

## How to call Random Port Number Generator

- 1 Get an API key
[Get an API key](/billing/checkout/?plan=free). Sign up free for a bearer token. 1,000 credits/month, no card.
- 2 Assemble the JSON body
Required fields:. See the Request body table below for the full schema.
- 3 POST to`https://api.miniwebtool.com/v1/tools/random-port-number-generator/run`
Headers:`Authorization: Bearer <key>`and`Content-Type: application/json`. Copy-paste snippets in 7 languages are under Code examples.
- 4 Parse the response
Envelope:`{request_id, tool, tool_version, credits_used, result}`. The typed output lives in`result`.

## Frequently asked

What does the Random Port Number Generator API do? ▾
Generate random network port numbers in standard or custom ranges. Use it to add this utility without rebuilding formulas, validation, examples, and documentation.
How much does one call to Random Port Number Generator cost? ▾
1 credit per successful call. Failed calls (validation errors, 5xx) don't bill.
What parameters does the Random Port Number Generator API require? ▾
Required fields: (none). Full schema at /v1/openapi.json.
Is the Random Port Number Generator API deterministic? ▾
This tool's output may vary (e.g. random generation). Version: 2026-04-22.
Can an AI agent call the Random Port Number Generator API? ▾
Yes. Connect to https://api.miniwebtool.com/v1/mcp over the Model Context Protocol. The agent discovers `random-port-number-generator` with its JSON Schema automatically, so the model can plan while MiniWebtool handles the exact tool result.
What format does the API return? ▾
JSON with a stable envelope: `{request_id, tool, tool_version, credits_used, result}`. Errors are RFC 7807 `application/problem+json`.

## Use from an AI agent

Every endpoint on this site is also exposed via the [Model Context Protocol](/docs/#mcp) at`https://api.miniwebtool.com/v1/mcp`. Claude, Cursor, and any MCP-capable agent can discover this tool (`random-port-number-generator`) and its JSON Schema automatically — no client codegen.

```text
# List tools the agent can call
curl -s https://api.miniwebtool.com/v1/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' \
 | jq '.result.tools[] | select(.name=="random-port-number-generator")'
```

## Related random tools

[
Random Color Generator
Generate random HEX, RGB, and HSL colors with optional harmony rules.
](/tools/random-color-generator/) [
Random Integer Generator
Generate random integers with optional uniqueness, sorting, exclusions, and see…
](/tools/random-integer-generator/) [
Random Decimal Number Generator
Generate random decimal numbers between 0 and 1 with configurable precision.
](/tools/random-decimal-number-generator/) [
Random Letter Generator
Generate random letters with case, vowel/consonant, and duplicate controls.
](/tools/random-letter-generator/)
© 2026 miniwebtool. API is a separate product from the consumer site. [Terms](https://miniwebtool.com/about/terms-and-disclaimer/#api-terms) [Privacy](https://miniwebtool.com/about/privacy/#api-privacy) [consumer site →](https://miniwebtool.com)
