Download the PHP package naiuz/sdk without Composer

On this page you can find all versions of the php package naiuz/sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sdk

NeuronAI PHP SDK

The official PHP client for the NeuronAI API: speech synthesis and dialogue, voice cloning, transcription, chat completions, embeddings and rerank. It runs on PHP 8.2 to 8.5, sends its calls through any PSR-18 HTTP client, such as Guzzle or Symfony HttpClient, and depends only on the PSR interfaces and php-http/discovery.

Install

The SDK needs an HTTP client. If your project has none yet, add Guzzle: composer require guzzlehttp/guzzle.

Quickstart

Create an API key in your NeuronAI dashboard at https://my.neuronai.uz and put it in the NEURONAI_API_KEY environment variable.

The client

What's in it

Resource Methods
$client->tts synthesize, dialogue
$client->tts->jobs create, retrieve, audio, createAndWait
$client->voices list, retrieve, create, update, replaceAudio, delete
$client->stt transcribe
$client->chat->completions create, streamed or not
$client->models list
$client->embeddings create
$client->rerank create
$client->account balance, usage
$client->apiKeys list, create, retrieve, update, revoke

api.md lists every method with its parameters and what it returns. Methods are camelCase. Request fields are array keys, and result fields are properties, under the API's own names, such as voice_id and next_cursor.

Speech

tts->synthesize returns a SpeechAudio: the WAV file's bytes, and what the answer's headers say about them.

Property
audio string: the WAV file's bytes
content_type 'audio/wav'
cost the price billed, in credits (X-Cost)
character_count the characters billed (X-Character-Count); an emotion tag counts as one
balance your balance after the charge (X-Balance)
voice_custom whether the voice is one of your clones (X-Voice-Custom)
latency_ms how long the voice took (X-Latency-Ms)
replayed whether this answer replays an earlier call with the same Idempotency-Key
request_id the request's ID (X-Request-Id), to quote to support

The number properties are null when the answer lacks their header. save($path) writes the file, replacing one already there; it throws NeuronAIException naming the path when it can't, never a PHP warning, even where an error handler turns warnings into exceptions. var_dump() shows the audio's size rather than its bytes.

tts->dialogue renders a multi-speaker script into one WAV and returns a DialogueAudio, which adds where each turn sits in the audio:

Synthesis jobs

For a long text, queue a job instead of waiting on one call. tts->jobs->createAndWait creates the job, polls it every 2 seconds, and returns it once it has succeeded or failed:

Uploads

voices->create and voices->replaceAudio take the reference clip as ref_audio, and stt->transcribe takes the audio as file. A file is either of these:

Chat completions and streaming

With 'stream' => true, chat->completions->create returns a Stream once the answer starts. Loop over it for each ChatCompletionChunk:

Without stream, the result is the ChatCompletion body, with cost from the X-Cost header.

Embeddings and rerank

Embeddings are float vectors. Rerank's results keep the server's order: by relevance_score, highest first. Chat completions, models, embeddings and rerank return the API's own bodies, compatible with OpenAI's and Cohere's shapes, with cost attached from X-Cost when the answer sends it.

Lists and pages

voices->list and apiKeys->list return a Page: its data, its next_cursor, hasNextPage() and nextPage(). Loop over it with foreach to walk every item, fetching the pages as it goes:

Pass limit from 1 to 100. Cursors are opaque: pass a page's next_cursor back as cursor, and never build one.

Results, request IDs and raw responses

Results are readonly classes with typed properties, under the API's own names. An answer in the {data, request_id} envelope gives its data, with a request_id property: quote it to support. On the compatible endpoints, cost is attached the same way. Neither is a field of the body, so toArray() and json_encode() leave them out and give exactly what the API sent: read them from the result itself.

A field the SDK doesn't know yet is kept: toArray() and json_encode() include it. An enum field is a plain string, so a value the API adds later still arrives; compare it with an enum case's value, such as TtsJobStatus::Succeeded->value.

$client->withRawResponse() has the same resources and methods, each returning the result together with the answer's status and headers:

Errors

Everything the SDK throws is a NeuronAIException, in Naiuz\Exceptions\:

Status Class
400 BadRequestException
401 AuthenticationException
402 InsufficientQuotaException
403 PermissionDeniedException
404 NotFoundException
409 ConflictException
410 GoneException
413 PayloadTooLargeException
415 UnsupportedMediaTypeException
422 UnprocessableEntityException
429 RateLimitException, with retry_after in seconds
500 and above InternalServerException
any other APIException

Match on error_code, never on the message. The codes are stable; the messages are written for people and may change. The API's code is error_code, because PHP's own getCode() is taken: it gives the HTTP status. Naiuz\ErrorCode lists every code, and error_code stays a plain string, so a code added later still arrives:

An answer outside the API's envelope, such as a proxy's HTML page, still throws the class for its status; its error_code and type are null, and its message is the status text and the start of the body.

Timeouts, retries and cancelling

Per-call options

Every method takes an array of options after its own arguments:

Option
timeout seconds this call's attempts may take
max_retries retries for this call
extra_headers headers for this call, over the client's
idempotency_key the five idempotent calls only: the Idempotency-Key to send, at most 191 characters

Headers go on in this order, each over the ones before: the SDK's own, default_headers, the call's Idempotency-Key, then extra_headers.

Left out, or null. A key you leave out isn't sent. A null is sent as JSON null, which the API reads as "clear it": $client->voices->update($voiceId, ['ref_text' => null]) removes the transcript, while $client->voices->update($voiceId, ['name' => 'Support voice']) leaves it alone. In a multipart upload, a null is left out, since a form has no null. A key a method doesn't take, such as refText, is refused before anything is sent, rather than ignored by the API.

Types

Every request field and every result property is typed. Each request is an array whose keys PHPStan checks against an array shape named after the API's request schema, such as SynthesizeSpeechRequest or CreateVoiceRequest, which you can import with @phpstan-import-type from the resource that defines it. The enums VoiceCategory, TtsJobStatus and ApiKeyAccess, in Naiuz\Types\, give the values the API knows today, and a case may be passed where a request takes one.

Examples

examples/ holds eight programs: synthesizing to a file, a dialogue, an async job with waiting, cloning a voice, a transcription, streaming chat, embeddings with rerank, and managing API keys. Each reads its key from NEURONAI_API_KEY. To run one from this folder, run php examples/synthesize.php.

License

MIT


All versions of sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
php-http/discovery Version ^1.20
psr/http-client Version ^1.0
psr/http-factory Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package naiuz/sdk contains the following files

Loading the files please wait ...