> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AIMLAPI 集成

> 使用 LangChain Python 集成 AIMLAPI LLM。

> [!WARNING]
>
> **您当前所在的页面正在记录 AI/ML API 模型作为文本完成模型的使用方法。许多最新和最受欢迎的 AI/ML API 模型是 [对话完成模型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md)。**
>
> 您可能正在寻找 [AI/ML API 对话文档](https://docs.aimlapi.com/)。

本页面帮助您开始使用 AI/ML API 文本完成模型。

## 概述

### 集成细节

| 类 | 包 | 本地 | 可序列化 | JS 支持 | 下载 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: | :-: |
| `AimlapiLLM` | `langchain-aimlapi` | ❌ | beta | ❌ | ![PyPI - 下载](https://img.shields.io/pypi/dm/langchain-aimlapi?style=flat-square\&label=%20) | ![PyPI - 版本](https://img.shields.io/pypi/v/langchain-aimlapi?style=flat-square\&label=%20) |

### 模型特性

| [工具调用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md) | [结构化输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/structured-output.md) | [图像输入](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#多模态) | 音频输入 | 视频输入 | [Token 级流式输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/streaming.md) | 原生异步 | [Token 使用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#token-使用) | [Logprobs](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#对数概率) |
| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |

## 设置

要访问 AI/ML API 模型，您需要创建一个账户，获取一个 API 密钥，并安装 `langchain-aimlapi` 集成包。

### 凭证

前往 [aimlapi.com](https://aimlapi.com/app/?utm_source=langchain\&utm_medium=github\&utm_campaign=integration) 注册并生成 API 密钥。完成后，设置 `AIMLAPI_API_KEY` 环境变量：

```python theme={null}
import getpass
import os

if not os.getenv("AIMLAPI_API_KEY"):
    os.environ["AIMLAPI_API_KEY"] = getpass.getpass("Enter your AI/ML API key: ")
```

要启用模型调用的自动跟踪，设置您的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```python theme={null}
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
```

### 安装

LangChain AI/ML API 集成位于 `langchain-aimlapi` 包中：

```python theme={null}
pip install -qU langchain-aimlapi
```

## 实例化

现在我们可以实例化我们的模型对象并生成文本完成：

```python theme={null}
from langchain_aimlapi import AimlapiLLM

llm = AimlapiLLM(
    model="openai/gpt-5-5",
    temperature=0.5,
    max_tokens=1024,
)
```

## 调用

```python theme={null}
response = llm.invoke("Explain the bubble sort algorithm in Python.")
print(response)
```

```text theme={null}
Bubble sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent items, and swaps them when they are out of order. The process repeats until the entire list is sorted. While easy to understand and implement, bubble sort is inefficient on large datasets because it has quadratic time complexity.
```

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.