Continue → Overview

Gender API for PHP

Use the PHP client in a web application, queue worker or command while preserving nullable results and the evidence behind every classification.

100 free credits every day. No card.

Create one configured client

The PHP client targets PHP 8.1 and later. Install it through Composer, read the key from configuration backed by an environment variable, and construct the client in your dependency container. Reusing one configured service keeps authentication and timeout policy out of controllers and jobs.

Pass a two-letter country code when your record has a trustworthy country field. Read the result as an array containing gender plus its probability, confidence, evidence count and source. Keep gender nullable in DTOs and database columns so an unknown answer is not coerced into a category.

Do not place lookup calls in a Blade template or a synchronous page loop. Resolve data in an application service, and move large enrichments to a queue or the managed file workflow.

PHP 8.1+
use NameGender\Client;

$client = new Client($_ENV['NAMEGENDER_API_KEY']);
$result = $client->name('Ayşe', country: 'TR');

echo $result['gender'] ?? 'unknown';
echo $result['probability'];
echo $result['source'];

Use bulk calls in queues and imports

When an import contains multiple records, collect independent lookup keys and send them through the bulk method. Deduplicate the combination of normalized name and country first, then map the returned values back to every original row.

Chunk work above the request limit and persist progress after each chunk. A queue retry can then resume from a known boundary. Keep business rules such as a minimum probability outside the HTTP client so they can change without rewriting transport code.

For a one-time spreadsheet, direct upload is usually simpler than building a Laravel import job. The dashboard previews the columns, estimates the credit cost and returns an enriched file without placing long network work inside a web request.

Bulk request
$results = $client->bulk(['Ayşe', 'Mehmet', 'Priya']);

foreach ($results as $result) {
    if (($result['probability'] ?? 0) >= 90) {
        // Apply your documented rule.
    }
}

Separate null, validation and transport errors

A successful response with gender set to null means there was not enough evidence. It should not trigger the same retry path as a connection timeout. Validation and authentication responses require a code or configuration change, while rate and eligible server failures may be retried with bounded backoff.

Set timeouts suitable for your request path. A page response should fail fast and fall back neutrally; a queue worker can wait longer and retry. In either case, avoid swallowing the status into a blank field that cannot be diagnosed later.

Exclude API keys and full customer records from logs, exception context and monitoring breadcrumbs. A request identifier, status, latency and internal record key are normally sufficient for tracing without copying personal data into another system.

Questions

Which PHP versions are supported?

The client targets PHP 8.1 and later.

Can I use it in Laravel or Symfony?

Yes. Register one configured client in the service container and inject it into the application service that owns enrichment.

Should unknown throw an exception?

No. Unknown is a valid successful result and should remain nullable.

How should I process a large import?

Use bounded bulk chunks in a queue, or upload the CSV/XLSX file through the dashboard for a one-time job.

Related pages

Gender API for Python

Call the NameGender API from Python, send country-aware and bulk lookups, handle unknown results, and keep probability and evidence fields in your pipeline.

Gender API for JavaScript

Use the NameGender JavaScript client in Node.js, Deno or Bun. See country-aware lookups, bulk requests, error handling and safe API-key placement.

Bulk gender detection from CSV and Excel

Upload a CSV or XLSX name list and get a gender column back, with confidence fields, automatic deduplication and the cost shown before charging.

How to compare name-to-gender APIs without trusting anyone's marketing

What to measure before you pick a vendor, why a single accuracy percentage tells you nothing, and how to run the same test on all of them — including us.

probability, confidence and total_names: reading a gender response properly

Reading the gender field alone discards everything that says whether to believe it. What each response field means and the thresholds behind confidence.

Check it against your own list

Every number on this page is reproducible with a free key. If your data breaks it, that is the more interesting result.