DEVUP Docs
Back to Dashboard

Integrations

PHP

openai-php/client is the most widely used OpenAI client for PHP. Point its base URI at DEVUP AI and the same code calls DEVUP AI models: chat, streaming, tool calling, JSON-schema output, and embeddings.

Requirements

Install openai-php/client with Composer

bash
composer require openai-php/client guzzlehttp/guzzle

openai-php/client needs a PSR-18 HTTP client; Guzzle is the one used here. When Composer asks to trust php-http/discovery, allow it:

bash
composer config allow-plugins.php-http/discovery true

Set environment variables

export DEVUP_API_KEY="your-key"

The examples below are one PHP file. It starts with <?php, and each example continues from the previous one.

Connect openai-php/client to DEVUP AI

php
require __DIR__ . '/vendor/autoload.php';

$client = OpenAI::factory()
    ->withApiKey(getenv('DEVUP_API_KEY'))
    ->withBaseUri('https://api.devupai.com/v1')
    ->make();

$response = $client->chat()->create([
    'model' => 'deepseek-ai/DeepSeek-V4-Pro',
    'messages' => [
        ['role' => 'user', 'content' => 'Reply with exactly: Salam DEVUP'],
    ],
]);

echo $response->choices[0]->message->content, PHP_EOL;

Output: Salam DEVUP

Client options

MethodValueWhy
withApiKeygetenv('DEVUP_API_KEY')Reads your DEVUP AI key from the environment.
withBaseUrihttps://api.devupai.com/v1Sends every request to DEVUP AI.
make—Builds the client.

Stream chat completions in PHP

createStreamed returns chunks as the model generates them.

php
$stream = $client->chat()->createStreamed([
    'model' => 'deepseek-ai/DeepSeek-V4-Pro',
    'messages' => [
        ['role' => 'user', 'content' => 'Count from 1 to 5, separated by spaces.'],
    ],
]);

foreach ($stream as $chunk) {
    echo $chunk->choices[0]->delta->content ?? '';
}
echo PHP_EOL;

Output: 1 2 3 4 5

Tool calling in PHP

The first request returns the tool the model wants to call. Run it, add the assistant message with toArray() and your result as a tool message, then send the conversation back.

php
$tools = [[
    'type' => 'function',
    'function' => [
        'name' => 'get_order_status',
        'description' => 'Look up the delivery status of an order by its ID.',
        'parameters' => [
            'type' => 'object',
            'properties' => ['order_id' => ['type' => 'string']],
            'required' => ['order_id'],
        ],
    ],
]];

$messages = [['role' => 'user', 'content' => 'What is the status of order A-100?']];
$first = $client->chat()->create([
    'model' => 'deepseek-ai/DeepSeek-V4-Pro',
    'messages' => $messages,
    'tools' => $tools,
]);

$call = $first->choices[0]->message->toolCalls[0];
$args = json_decode($call->function->arguments, true);
$status = 'Order ' . $args['order_id'] . ' has shipped. Tracking number: DZ-4471.';

$messages[] = $first->choices[0]->message->toArray();
$messages[] = ['role' => 'tool', 'tool_call_id' => $call->id, 'content' => $status];

$final = $client->chat()->create([
    'model' => 'deepseek-ai/DeepSeek-V4-Pro',
    'messages' => $messages,
    'tools' => $tools,
]);

echo $call->function->name, ': ', $final->choices[0]->message->content, PHP_EOL;

The tracking number DZ-4471 only exists in your tool result, so seeing it in the final answer shows the round trip worked.

Structured output with a JSON schema

php
$response = $client->chat()->create([
    'model' => 'deepseek-ai/DeepSeek-V4-Pro',
    'messages' => [
        ['role' => 'user', 'content' => 'Which city is the capital of Algeria?'],
    ],
    'response_format' => [
        'type' => 'json_schema',
        'json_schema' => [
            'name' => 'capital',
            'strict' => true,
            'schema' => [
                'type' => 'object',
                'properties' => [
                    'city' => ['type' => 'string'],
                    'country' => ['type' => 'string'],
                ],
                'required' => ['city', 'country'],
                'additionalProperties' => false,
            ],
        ],
    ],
]);

$capital = json_decode($response->choices[0]->message->content, true);
echo $capital['city'], ', ', $capital['country'], PHP_EOL;

Output: Algiers, Algeria

Prefer descriptive field names such as city over name. See Structured Outputs.

Create embeddings in PHP

php
$embedding = $client->embeddings()->create([
    'model' => 'BAAI/bge-m3',
    'input' => 'Salam DEVUP',
]);

echo count($embedding->embeddings[0]->embedding), PHP_EOL;

Output: 1024

BAAI/bge-m3 returns 1024-dimensional vectors. See Embeddings.

Choosing models

Use the exact catalog ID as model. Tool calling needs a model whose catalog entry supports it. See Models and Tool Calling.

Troubleshooting

  • Authentication error (401)Set DEVUP_API_KEY in the same terminal that runs your script, without a Bearer prefix.
  • cURL error 60: SSL certificate problem (Windows)

    PHP on Windows ships without CA certificates. Download cacert.pem from https://curl.se/ca/cacert.pem, then set both curl.cainfo and openssl.cafile to its full path in php.ini. Keep SSL verification on.

    ini
    curl.cainfo = "C:\path\to\cacert.pem"
    openssl.cafile = "C:\path\to\cacert.pem"
  • A structured field comes back as an identifierWith a JSON-schema response format, a field called name can be filled with an identifier instead of a value. Use a descriptive key such as city.
  • The model answers without calling your toolModels can answer simple questions on their own. Use tools for data the model cannot know, and a model whose catalog entry supports tool calling.

FAQ

Can I use openai-php/client with DEVUP AI?

Yes. Build the client with withBaseUri('https://api.devupai.com/v1') and your DEVUP AI key; chat, streaming, tools, JSON-schema output and embeddings then go to DEVUP AI.

Which PHP version do I need?

openai-php/client requires PHP 8.2 or newer, with the openssl and curl extensions enabled.

How is PHP usage billed on DEVUP AI?

Every request is a regular DEVUP AI API call, metered in Algerian Dinar on your account.

How do I fix cURL error 60 in PHP on Windows?

Download cacert.pem from curl.se and set curl.cainfo and openssl.cafile to its path in php.ini. Do not turn off SSL verification.

Does streaming work with openai-php/client on DEVUP AI?

Yes. createStreamed returns chunks as the model generates them.

Can I create embeddings from PHP on DEVUP AI?

Yes. Call $client->embeddings()->create with a catalog embedding model such as BAAI/bge-m3, which returns 1024-dimensional vectors.

Related integrations

  • Python: The official OpenAI Python SDK on DEVUP AI.
  • Node.js SDK: The official DEVUP AI SDK for Node.js.
  • OpenAI SDK: OpenAI SDKs pointed at DEVUP AI.
  • CrewAI: Multi-agent crews in Python.
  • LangChain: Chains and agents with LangChain.