---
title: "Execute code"
method: POST
path: "/tci/execute"
tags: ["Code Interpreter"]
---

# Execute code

`POST /tci/execute`

Executes the given code snippet and returns the output. Without a session_id, a new session is created to run the code. If you pass a valid session_id, the code runs in that session. This is useful for running multiple code snippets in the same environment, because dependencies and similar things are persisted
between calls to the same session.

## Request body

- ExecuteRequest
  - `code` string, required — Code snippet to execute.
  - `files` object[] — Files to upload to the session. If present, files are uploaded before executing the given code.
    - `content` string, required
    - `encoding` 'string' | 'base64', required — Encoding of the file content. Use `string` for text files such as code, and `base64` for binary files, such as images.
    - `name` string, required
  - `language` 'python', required — Programming language for the code to execute. Currently only supports Python.
  - `session_id` string — Identifier of the current session. Used to make follow-up calls. Returns an error if the session does not belong to the caller or has expired.

## Response `200`

Execute Response

- union — The result of the execution. If successful, `data` contains the result and `errors` is null. If unsuccessful, `data` is null and `errors` contains the errors.
  - object
    - `errors` unknown, required
    - `data` object, required
      - `outputs` union[], required
        - union
          - object — Outputs that were printed to stdout or stderr
            - `type` 'stdout' | 'stderr', required
            - `data` string, required
          - object — Errors and exceptions that occurred. If this output type is present, your code did not execute successfully.
            - `data` string, required
            - `type` 'error', required
          - object
            - `data` object, required
              - …
            - `type` 'display_data' | 'execute_result', required
      - `session_id` string, required — Identifier of the current session. Used to make follow-up calls.
      - `status` 'success' — Status of the execution. Currently only supports success.
  - object
    - `data` unknown, required
    - `errors` union[], required
      - union
        - string
        - object

---

[API](https://skmtc.net/together/apis/together-apis.md) · [All operations](https://skmtc.net/together/apis/together-apis/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/together/together-apis/revisions/468edbdc879c/schema)
