> For the complete documentation index, see [llms.txt](https://smallso.gitbook.io/tencent-cloud-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/routine-invoke.md).

# routine\_invoke 方法

## 简要

调用给定无服务器云函数的指定例程，并获取例程的实际返回值。

```python
def routine_invoke(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    routine_name: str,
    routine_parameter: dict = None,
    function_version: str = None,
    function_async: bool = False
) -> object
```

{% content-ref url="/pages/-M238eWqdKCF8lEGGB3s" %}
[使用例程组织无服务器云函数](/tencent-cloud-sdk/python-best-practices/serverless-functions/native-invoke/routine.md)
{% endcontent-ref %}

## 参数

该方法的参数和参数描述如下：

| 参数                 | 类型   | 必选 | 描述                                                                           |
| ------------------ | ---- | -- | ---------------------------------------------------------------------------- |
| region\_id         | str  | 是  | <p>调用的无服务器云函数所在数据中心的唯一标识符。</p><p>例如：<code>ap-shanghai</code></p>             |
| namespace\_name    | str  | 是  | <p>调用的无服务器云函数所在命名空间的名称。</p><p>例如：<code>default</code></p>                    |
| function\_name     | str  | 是  | <p>调用的无服务器云函数名称。</p><p>例如：<code>arithmetic</code></p>                        |
| routine\_name      | str  | 是  | <p>调用的无服务器云函数的例程名称。</p><p>例如：<code>addend</code></p>                         |
| routine\_parameter | dict | 否  | <p>调用的无服务器云函数关键字参数。</p><p>例如：<code>{ 'value1': 10, 'value2': 20 }</code></p> |
| function\_version  | str  | 否  | <p>调用的无服务器云函数版本名称。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认调用最新版本。</p>        |
| function\_async    | bool | 否  | <p>调用的无服务器云函数是否以异步的方式运行。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认以同步方式运行。</p> |

## 返回值

该方法返回给定无服务器云函数的指定例程调用的实际返回值。返回值视参数的值不同而异，详情请参阅方法 `easy_invoke` 的返回值描述。

{% content-ref url="/pages/-M-j9M4sZsfoBrs320Ri" %}
[easy\_invoke 方法](/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/easy-invoke-method.md)
{% endcontent-ref %}

## 异常

该方法可能会主动引发以下异常：

#### ValueError

参数值或类型不符合预期。

#### InvokeError

给定无服务器云函数在调用过程中遇到错误，这通常是由于无服务器云函数所运行的代码存在异常。

#### ActionError

Tencent Cloud API 错误。例如访问凭据无效、给定无服务器云函数不存在等均会引发该异常。

## 示例

下面我们将通过一段 Python 代码向您演示如何使用该方法：

```python
return_value: int = function_client.routine_invoke(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'arithmetic',
    routine_name = 'addend',
    routine_parameter = {
        'value1': 10,
        'value2': 20
    }
)
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.5


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/routine-invoke.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
