# Vercel AI SDK

Source: https://convergingthought.com/docs/integrations/ai-sdk

> Use Internalize with generateText, streamText, and your own tools.



Use `@ai-sdk/openai-compatible` to target Chat Completions explicitly. Keep the provider and credentials on your server.

```bash
npm install ai @ai-sdk/openai-compatible
```

```ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";

const internalize = createOpenAICompatible({
  name: "internalize",
  baseURL: "https://convergingthought.com/v1",
  apiKey: process.env.INTERNALIZE_API_KEY,
});

const result = await generateText({
  model: internalize("glm-5.3"),
  prompt: "Explain test-time training with an example.",
  maxRetries: 0,
});
console.log(result.text);
```

## Use an adapter [#use-an-adapter]

Resolve the subject in your authenticated server handler, then include `headers: { "X-Internalize-Subject": subject }` in `generateText` or `streamText`. Headers belong to that request; avoid mutating a shared provider for each customer.

An unseen subject starts from base. After learning activates a version, subsequent requests with the same subject route to it automatically. To compare against base, omit the subject entirely in a separate request.

## Tools [#tools]

The AI SDK converts ordinary function tools into the Chat Completions format. Define `inputSchema` and an `execute` handler using the SDK's `tool` helper. Your application owns the handler and its authorization. Validate tool arguments before using them for external actions.

For `internalize`, expose only a content argument. Bind the authorized subject in the server closure and store a durable idempotency key for that tool invocation. Do not generate a fresh key on each handler retry. Follow [Add learning](/docs/integrations/learning) for activation and long-running job semantics.

## Streaming [#streaming]

`streamText` can parse Internalize's SSE responses. Text and tool arguments are emitted after the complete model response passes validation, so the current stream is buffered. Show a waiting state until the first content arrives. Cancelling your UI stream does not cancel the durable model job.

## Supported surface [#supported-surface]

Use text prompts, text conversation messages, function tools, temperature, and output-token limits. Images, audio, embeddings, Responses-only features, and structured `json_schema` output are not available. Do not silently fall back to another model when an adapter request fails.

The protocol tests exercise `generateText`, `streamText`, and function-call parsing using the installed AI SDK against the same gateway serializers. They use a local transport and do not measure model quality or live provider availability.

See the [official compatible-provider guide](https://ai-sdk.dev/providers/openai-compatible-providers) for provider configuration and [the tool guide](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) for application-side execution.
