# get()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/models/get/
Language: zh

`api.models.get(id) → Promise<AssistantSession>`

由 id 重新打开会话, 其配置和对话保持不变 。 这是一条线能从重新开始中生存下来的原因 。

Status: GET /api/ai/models/:id · free · throws on 404

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string | 必填 | 届会代 届会代 , `assistant.id` 或 [(列表)](/zh/sdk/ref/models/list). |

## 返回值 {#returns}

A 音 A [助理会期](/zh/sdk/ref/assistant-session),在种类上与什么相同 `create()` 给了你:相同的配置,相同的ID, 和后面的谈话。

```javascript
// First run
const assistant = await api.models.create({ model: "gemini-3.5-flash" });
await db.save(userId, assistant.id);
await assistant.generate({ inputs: [{ type: "text", content: "My name is Zayd." }] });

// A week later, a different process
const again = await api.models.get(await db.load(userId));
await again.generate({ inputs: [{ type: "text", content: "What is my name?" }] });
// It knows — the conversation came back with the session.
```

> **身份证是你唯一要保存的东西**
>
> 其它一切——模型、设置、计划、历史——都在服务器上,将会议所属的代号放在会话旁边,不需要再坚持了。

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| session_not_found | 404 | 这笔账户的任何一届会议都未包含这一ID,包括一个错误的ID。 |

It **throws** rather than returning `null`, so a missing session is an exception to catch, not a value to test.

```javascript
import { IaGenifyError } from "iagenify";

async function resume(api, id, model) {
  try {
    return await api.models.get(id);
  } catch (err) {
    if (err instanceof IaGenifyError && err.status === 404) {
      // Deleted, or belonging to another account. Start a fresh one.
      return api.models.create({ model });
    }
    throw err;
  }
}
```

属于另一个账户的届会也回答同样的问题 `404`:查找范围是针对打电话者,因此一个账户无法达到甚至无法检测到另一个会话。

## 以内存创建的会话: 假 {#memory-false}

......它仍然存在, `get()` 仍然返回它, 因为配置已被记录。 没有的则是一个对话框: 重新打开它, 给您同样的设置和空白板块 。

- [list()](/zh/sdk/ref/models/list): 查找您没有保存的id。
- [getHistory()](/zh/sdk/ref/assistant-session/get-history): 阅读所说的话,而不是继续。

```python
# First run
assistant = api.models.create(model="gemini-3.5-flash")
db.save(user_id, assistant.id)
assistant.generate(inputs=[{"type": "text", "content": "My name is Zayd."}])

# A week later, a different process
again = api.models.get(db.load(user_id))
again.generate(inputs=[{"type": "text", "content": "What is my name?"}])
# It knows — the conversation came back with the session.
```

```python
from iagenify import IaGenifyError

def resume(api, session_id, model):
    try:
        return api.models.get(session_id)
    except IaGenifyError as error:
        if error.status == 404:
            # Deleted, or belonging to another account. Start a fresh one.
            return api.models.create(model=model)
        raise
```
