What Is an AI SDK? A Guide for PHP Developers

AI SDK for PHP: How to Build Your First Agent

An AI SDK is a software development kit that lets your code talk to AI models through ordinary functions instead of raw HTTP requests. It handles provider differences, tool calling, and response parsing, so you write application logic rather than plumbing. Most languages now have several. In PHP, Laravel’s official AI SDK is the most direct option, and Symfony and framework-neutral libraries cover the rest.

Key takeaways

  • An AI SDK wraps one or more model providers behind a single programming interface.
  • It sits between a low-level API client and a full agent framework.
  • Provider coverage, stability, framework fit, and testing support are the criteria that matter most.
  • In PHP, Laravel ships a first-party AI SDK; Symfony AI and community libraries are alternatives.
  • Frameworks without an SDK can follow the same pattern with one agent class and an adapter.

How an AI SDK is structured

Most AI SDKs are built in layers. Knowing the layers helps you judge what a given SDK actually covers.

  • Provider adapters: One adapter per provider translates a common request format into each provider’s API and back.
  • Core interface: The methods your code calls, such as sending a prompt, streaming a reply, or requesting structured output.
  • Agent layer: An optional abstraction that bundles a model, instructions, and tools into a reusable unit and runs the tool-call loop.
  • Framework integration: Glue that connects the SDK to your framework’s config, dependency injection, queues, and logging.
  • Testing support: Fakes or fixtures that replace live provider calls in automated tests.

Simpler packages stop after the first two layers. Fuller SDKs cover all five, which is where most of the time savings come from.

AI SDK vs API client vs agent framework

Three kinds of tools get called “AI SDKs,” and they solve different problems.

  • API client. A thin wrapper around one provider’s API. It turns HTTP calls into method calls and returns the provider’s response as is. It’s a good fit when you use one provider and want minimal abstraction.
  • AI SDK. A provider-neutral layer over several APIs. It normalizes requests and responses, runs tool calls, and usually adds streaming, structured output, and testing helpers. It’s a good fit for most application features.
  • Agent framework. A larger system for multi-step, multi-agent workflows, often with memory, planning, and orchestration built in. It’s a good fit for complex autonomous tasks, but it adds concepts and moving parts that simple features don’t need.

The lines blur in practice. Many AI SDKs now include an agent layer, and some agent frameworks ship their own provider clients.

What to look for in an AI SDK

Five criteria separate a good fit from a frustrating one:

  • Provider coverage: Check that the providers and models you need today are supported, plus at least one fallback.
  • Stability: Look at release history and whether the API is marked stable or experimental. Young SDKs change method names often.
  • Framework fit: An SDK built for your framework reuses its config, dependency injection, and queues. A generic one needs that glue written by you.
  • Testing support: Built-in fakes let you test AI features without live calls or API spend.
  • Maintenance backing: First-party or well-funded projects tend to track provider changes faster than solo-maintained packages.

PHP AI SDKs measured against these criteria

  • Laravel AI SDK. Laravel’s first-party SDK, published as laravel/ai, scores well on framework fit, testing, and backing. It supports several providers, integrates with Laravel’s container, config, and queues, and ships with fakes for tests. It’s young, so check the docs for method changes between releases. For Laravel projects and new PHP projects, it’s the strongest starting point.
  • Symfony AI. Symfony’s components offer broad provider coverage and close Symfony integration through a bundle. The Agent component is marked experimental, so stability is the main trade-off today.
  • Framework-neutral libraries. Packages such as openai-php/client are API clients rather than full SDKs. They’re stable and widely used, but they cover one provider and leave the agent layer, provider switching, and framework glue to you.

Outside PHP, the Vercel AI SDK is the best-known option for TypeScript, and model providers publish their own SDKs for several languages.

Using the AI SDK pattern in a framework without one

Some frameworks, such as Laminas, don’t include an AI SDK. You can still follow the same pattern Laravel’s SDK uses: one class per agent, holding its instructions, tools, and result type.

In Laminas, that means three pieces:

  1. An agent class that takes a model client and its tools through the constructor and exposes one method, such as answer(string $question, UserIdentity $user).
  2. A factory that reads the API key, model, timeout, and retry count from module config.
  3. One service_manager entry in module.config.php mapping the agent to its factory.

A minimal agent class looks like this:

final class SupportAgent
{
    private const INSTRUCTIONS =
        'You answer support questions. Be brief. Never guess a ticket status.';

    public function __construct(
        private ModelClient $client, // your provider adapter
        private TicketLookupTool $ticketLookup,
    ) {}

    public function answer(string $question, UserIdentity $user): SupportReply
    {
        $text = $this->client->run(
            instructions: self::INSTRUCTIONS,
            prompt: $question,
            tools: [$this->ticketLookup->forUser($user)],
        );

        return new SupportReply($text);
    }
}

ModelClient is a small interface you define over a provider library, so a provider switch touches one adapter. Authentication stays outside the agent, which receives an already-resolved user.

This works, but you own the adapter, the tool loop, retries, and queue setup. That ongoing upkeep is the main reason teams pick a framework with an SDK built in.

When you don’t need an AI SDK

An SDK isn’t always worth the dependency. You can skip it when:

  • You make one simple call, such as summarizing text, with no tools or structured output.
  • You’re prototyping and expect to throw the code away.
  • You need a provider feature so new that no SDK supports it yet.

Once a feature grows to several prompts, tools, or providers, the hand-written code starts to look like a small SDK. That’s usually the point to adopt a real one.

Frequently asked questions

Is “AI SDK” a specific product?

No. It’s a general term for any software kit that connects code to AI models. Several products use it in their names, including the Vercel AI SDK for TypeScript and the Laravel AI SDK for PHP.

Does an AI SDK lock me into one provider?

No, that’s the main reason to use one. A provider-neutral SDK lets you switch models through configuration. Lock-in comes from provider-specific features, such as a particular file or search API, so isolate those calls behind your own interface.

Can I keep my existing PHP app and run only the AI feature on Laravel?

Yes. Run the agent as a separate Laravel service behind an API endpoint. Your main app calls it over HTTP, keeps authentication, and passes the resolved user ID with each request.

Are AI SDKs only for chatbots?

No. Common uses include classifying support tickets, extracting fields from documents, summarizing records, generating product descriptions, and turning free text into structured data. Many of these run in the background with no chat interface at all.

Kyle Bartlett