# API Code Examples

This page provides code examples for running the APIs in Python.

Before running any of the scripts, run `export ARCEE_API_TOKEN=$YOUR_TOKEN`.

### List Available Workflows

```python
import requests
import os

# Setup
API_BASE_URL = "https://orchestra.arcee.ai/api/v1/workflow"
API_KEY = os.environ.get("ARCEE_API_TOKEN")
headers = {"Authorization": f"Bearer {API_KEY}"}

# List workflows
response = requests.get(f"{API_BASE_URL}/workflows", headers=headers)
print(response.json())
```

### Workflow Execution

```python
import requests
import os

# Setup
API_BASE_URL = "https://orchestra.arcee.ai/api/v1/workflow"
API_KEY = os.environ.get("ARCEE_API_TOKEN")
headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
workflow_id = "YOUR_WORKFLOW_ID"

# Execute a workflow
payload = {"prompt": "Tell me a joke about the weather"}
response = requests.post(f"{API_BASE_URL}/workflows/{workflow_id}/execute", 
                        headers=headers, 
                        json=payload)

print(response.json())
```

### Workflow Execution Steps

```python
import requests
import os

# Setup
API_BASE_URL = "https://orchestra.arcee.ai/api/v1/workflow"
API_KEY = os.environ.get("ARCEE_API_TOKEN")
headers = {"Authorization": f"Bearer {API_KEY}"}
workflow_id = "YOUR_WORKFLOW_ID"
run_id = "YOUR_RUN_ID"

# Get workflow execution steps
response = requests.get(f"{API_BASE_URL}/workflows/{workflow_id}/runs/{run_id}/steps", headers=headers)
run_details = response.json()
print(run_details)
```

### Execution History

```python
import requests
import os

# Setup
API_BASE_URL = "https://orchestra.arcee.ai/api/v1/workflow"
API_KEY = os.environ.get("ARCEE_API_TOKEN")
headers = {"Authorization": f"Bearer {API_KEY}"}
workflow_id = "YOUR_WORKFLOW_ID"
limit = 10
offset = 0

# Get execution history
response = requests.get(f"{API_BASE_URL}/workflows/{workflow_id}/runs?limit={limit}&offset={offset}", headers=headers)
print(response.json())
```

### Workflow Diagram

```python
import requests
import os

# Setup
API_BASE_URL = "https://orchestra.arcee.ai/api/v1/workflow"
API_KEY = os.environ.get("ARCEE_API_TOKEN")
headers = {"Authorization": f"Bearer {API_KEY}"}
workflow_id = "YOUR_WORKFLOW_ID"

# Get workflow diagram
response = requests.get(f"{API_BASE_URL}/workflows/{workflow_id}/diagram", headers=headers)
print(response.json())
```


---

# Agent Instructions: 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:

```
GET https://docs.arcee.ai/arcee-orchestra/workflows/api-invocation/api-code-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
