> Documentation index: https://metorial.com/llms.txt. Every page is available as Markdown by adding .md to its URL.

# Metorial notes for AI code generators and coding agents
URL: https://metorial.com/docs/build/guides/notes-for-ai-code-generators

The current way to use Metorial in code: metorial 3.x on npm, 2.x on PyPI, metorial.connect() with an adapter, and the names generated code gets wrong.

---

If you generate code against Metorial, use `metorial.connect()` with an adapter, `metorial` 3.x on npm or 2.x on PyPI, and the names on this page. Older posts and examples use names that no longer compile.

**What you'll learn**

* The current packages and versions
* The recommended program in TypeScript and Python
* Old names and what replaced them

**Before you start**

* A secret [API key](https://metorial.com/docs/build/api) in `METORIAL_API_KEY`
* A provider deployment ID in `METORIAL_PROVIDER_DEPLOYMENT_ID`. Create one with `metorial-admin providers deployments create --provider-id metorial-search --name "Metorial Search"`.

## Current packages

| Package                                                       | Version on 2026-11-22       | Use                                      |
| ------------------------------------------------------------- | --------------------------- | ---------------------------------------- |
| `metorial` (npm)                                              | 3.3.6                       | TypeScript and JavaScript SDK            |
| `@metorial/ai-sdk`                                            | 3.0.9                       | Adapter for the Vercel AI SDK            |
| `@metorial/openai`, `@metorial/anthropic`, `@metorial/google` | 3.0.11                      | Adapters for the model SDKs              |
| `@metorial/langchain`                                         | 3.0.9                       | Adapter for LangChain and LangGraph      |
| `metorial` (PyPI)                                             | 2.7.0, Python 3.10 or later | Python SDK with every adapter built in   |
| `@metorial/cli`, `@metorial/admin`                            | 0.1.9                       | The `metorial` and `metorial-admin` CLIs |

Python adapters are functions in the `metorial` package: `metorial_openai`, `metorial_anthropic`, `metorial_google`, `metorial_mistral`, `metorial_openai_compatible`, `metorial_langchain`, `metorial_langgraph`, `metorial_openai_agents`, `metorial_llamaindex`, `metorial_crewai`, `metorial_google_adk`, `metorial_pydantic_ai`, `metorial_autogen` and `metorial_haystack`.

## The recommended program

**TypeScript**

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

```typescript
import { openai } from '@ai-sdk/openai';
import { metorialAiSdk } from '@metorial/ai-sdk';
import { generateText, stepCountIs } from 'ai';
import Metorial from 'metorial';

let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY! });

let session = await metorial.connect({
  adapter: metorialAiSdk(),
  providers: [{ providerDeploymentId: process.env.METORIAL_PROVIDER_DEPLOYMENT_ID! }]
});

let result = await generateText({
  model: openai('gpt-4o-mini'),
  prompt: 'Search the web for the latest news about AI agents and summarize the top 3 stories.',
  stopWhen: stepCountIs(10),
  tools: session.tools()
});

console.log(result.text);
```

**Python**

```bash
pip install metorial openai-agents
```

```python
import asyncio
import os

from agents import Agent, Runner
from metorial import Metorial, metorial_openai_agents


async def main():
    metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])

    session = await metorial.connect(
        adapter=metorial_openai_agents(),
        providers=[
            {"provider_deployment_id": os.environ["METORIAL_PROVIDER_DEPLOYMENT_ID"]}
        ],
    )

    agent = Agent(
        name="Research assistant",
        instructions="Use the Metorial tools to answer the question.",
        tools=session.tools(),
    )
    result = await Runner.run(
        agent,
        "Search the web for the latest news about AI agents and summarize the top 3 stories.",
    )
    print(result.final_output)


asyncio.run(main())
```

For a user's own account, add `providerAuthConfigId` (`provider_auth_config_id` in Python) to the provider entry. The ID comes from a setup session. See [Let each user connect their own account](https://metorial.com/docs/build/sdk/oauth).

## Mistakes to avoid

Generated code often contains these. None of them is current:

* `callbackUri` on a setup session. The field is `redirectUrl`, or `redirect_url` in Python.
* `metorial.providers.setup_sessions` in Python. Use `metorial.provider_deployments.setup_sessions.create(...)`.
* `await` on Python resource calls. `provider_deployments.create`, `setup_sessions.create` and `sessions.create` are synchronous. Only `metorial.connect()` and `metorial.wait_for_setup_session()` are awaited.
* `import { MetorialAPIError } from 'metorial'` in TypeScript. The package does not export it. Use `isMetorialSDKError` from `@metorial/util-endpoint`. In Python, `MetorialAPIError`, `AuthenticationError` and `NotFoundError` are exported from `metorial`. See [Error handling](https://metorial.com/docs/build/sdk/error-handling).
* Tool filters of type `allow`. The types are `tool_keys`, `tool_regex` and `tool_categories`, in a `toolFilters` list on the provider entry.
* Relying on `pip install metorial` to bring a model SDK. Since 2.4.0 it installs none. Add `openai`, `anthropic` or your framework yourself.
* `google-generativeai`. The Python SDK moved to `google-genai` in 2.3.3.
* A synchronous Python client. It was removed in 2.3.0.
* A publishable key on the server. Sessions and MCP connections need a secret key that starts with `metorial_sk_`.
* `metorial integrations ...` in the CLI. The commands are `metorial setup`, `metorial tools`, `metorial schema`, `metorial call` and `metorial install`. Admin tasks use `metorial-admin`.

## Old names and current names

| Old                                                 | Current                                                          |
| --------------------------------------------------- | ---------------------------------------------------------------- |
| `serverDeployments` array                           | `providers` array                                                |
| `serverDeploymentId`                                | `providerDeploymentId`                                           |
| `oauthSessionId`                                    | `providerAuthConfigId`                                           |
| `metorial.oauth.sessions.create()`                  | `metorial.providerDeployments.setupSessions.create()`            |
| `metorial.oauth.waitForCompletion()`                | `metorial.providerDeployments.setupSessions.waitForCompletion()` |
| `metorial.withProviderSession(...)`, deprecated     | `metorial.connect({ adapter, providers })`                       |
| Python `with_provider_session()`                    | `await metorial.connect(adapter=..., providers=[...])`           |
| Python `metorial.adapters` module, removed in 2.4.0 | Adapter functions such as `metorial_openai`                      |

## Check generated code

Type-check TypeScript with `npx tsc --noEmit`. The old names fail at compile time. Then run the program and list the tool calls Metorial recorded:

```bash
metorial-admin sessions tool-calls list \
  --provider-deployment-id $METORIAL_PROVIDER_DEPLOYMENT_ID \
  --limit 5
```

## Next steps

* [Choose between the SDK, the REST API and plain MCP](https://metorial.com/docs/build/guides/sdk-rest-api-or-mcp): which path fits your stack
* [Framework guides](https://metorial.com/docs/build/frameworks/openai-agents-sdk): one complete program per framework
* [Use the docs in your AI client](https://metorial.com/docs/build/use-docs-in-your-ai-client): give a coding agent these docs over MCP