### Node.js Example: Server Setup
Source: https://docs.corti.ai/assistant/authentication
This snippet shows a basic Node.js server setup using Express, including logging the server's running status. It's part of a larger authentication example.
```javascript
const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
```
--------------------------------
### Cloning and Running the Example Project
Source: https://docs.corti.ai/assistant/guides/react-integration
Clone the example repository, navigate to the project directory, install dependencies, configure environment variables, and run the development server.
```bash
git clone https://github.com/corticph/corti-examples.git
cd corti-examples/embedded-assistant/react/basic-example
npm install
cp .env.example .env
# Edit .env with your credentials
npm run dev
```
--------------------------------
### Example of setting up a dictation session
Source: https://docs.corti.ai/sdk/dictation/overview
This snippet demonstrates how to initialize and start a dictation session. Ensure you have the necessary SDK components imported.
```javascript
const dictation = new Dictation();
dictation.start();
```
--------------------------------
### Quick Start HTML Example
Source: https://docs.corti.ai/sdk/dictation/overview
A basic HTML structure demonstrating how to use the Corti Dictation component. This example shows the component usage after the SDK has been loaded.
```html
```
--------------------------------
### Get Access Token Example
Source: https://docs.corti.ai/authentication/quickstart
This example demonstrates how to obtain an access token using the `getAccessToken` function and then log it to the console. It also includes basic error handling.
```javascript
getAccessToken().then(token => {
console.log("Access token:", token);
}).catch(err => {
console.error("Error fetching token:", err);
});
```
--------------------------------
### Basic Python Request Example
Source: https://docs.corti.ai/coding/cpt
A simple Python example demonstrating how to make a request. This snippet is a starting point and may require additional setup for full functionality.
```python
import requests
```
--------------------------------
### Forwarded GET Request to Proxy Example
Source: https://docs.corti.ai/assistant/proxy
Demonstrates an example of a GET request being forwarded to the proxy. This includes the HTTP method, URL, and version.
```http
GET https://proxy.example.com/api/interactions HTTP/1.1
Host: proxy.example.com
```
--------------------------------
### Forwarded GET Request to Upstream Example
Source: https://docs.corti.ai/assistant/proxy
Shows an example of a GET request forwarded from the proxy to an upstream service. This includes the target URL, HTTP version, and host header.
```http
GET https://assistant.eu.corti.app/api/interactions HTTP/1.1
Host: assistant.eu.corti.app
Corti-Forwarded-For: 192.168.1.100
Corti-Forwarded-Host: proxy.example.com
Corti-Forwarded-Proto: https
```
--------------------------------
### ICD-10 International Quick Start Example
Source: https://docs.corti.ai/coding/icd-10-int
This example demonstrates how to use the ICD-10 International system with specific system identifiers for inpatient and outpatient scenarios. It's a quick way to start using the system.
```shellscript
curl --request POST \
--url https://api.corti.ai/v1/classify \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{ \
"text": "Patient presents with fever and cough.", \
"system": "icd10int-inpatient" \
}'
```
--------------------------------
### CortiClient Constructor Example
Source: https://docs.corti.ai/sdk/dotnet/reference
Demonstrates how to instantiate the CortiClient using tenant name, environment, and authentication details. Ensure all required parameters are provided.
```csharp
// 1. Tenant + environment + auth (most common)\nnew CortiClient( tenantName, environment, \
```
--------------------------------
### Applying Configuration Early
Source: https://docs.corti.ai/assistant/configuration
Example of applying configuration as soon as the Assistant is ready, typically after the 'ready' event. This ensures a consistent user experience from the outset.
```javascript
ready
// Configure the Assistant as soon as it’s ready
```
--------------------------------
### Example API Request
Source: https://docs.corti.ai/authentication/overview
This example demonstrates how to make a GET request to the /v2/interactions endpoint, including the required Authorization and Tenant-Name headers.
```APIDOC
## GET /v2/interactions
### Description
Retrieves a list of interactions. This is an example endpoint to show authentication.
### Method
GET
### Endpoint
https://api.$environment.corti.app/v2/interactions
### Headers
- **Authorization** (string, required) - Must contain the bearer token returned from the OAuth server.
- **Tenant-Name** (string, required) - The tenant identifier where the request is executed. Default tenants typically use `base`, but enterprise setups may use a custom tenant name.
### Request Example
```bash
curl -X GET "https://api.$environment.corti.app/v2/interactions" \
-H "Authorization: Bearer {{access_token}}" \
-H "Tenant-Name: base"
```
### Response
#### Success Response (200)
- **interactions** (array) - A list of interaction objects.
#### Response Example
```json
{
"interactions": [
{
"id": "interaction-id-1",
"timestamp": "2023-10-27T10:00:00Z",
"type": "call"
}
]
}
```
```
--------------------------------
### CortiClient Initialization
Source: https://docs.corti.ai/sdk/js/reference
Demonstrates how to import and instantiate the CortiClient with necessary configuration parameters.
```APIDOC
## CortiClient Initialization
### Description
This section shows how to import the `CortiClient` class and create a new instance of it. The client requires configuration for the environment, tenant name, and authentication details.
### Method
```javascript
import { CortiClient } from "@corti/sdk";
const client = new CortiClient({
environment: "",
tenantName: "",
auth: { ... }, // see Authentication Guide
// Optional
headers: {
"X-Custom": "value"
}
});
```
### Parameters
#### Initialization Options
- **environment** (string) - Required - Specifies the Corti environment (e.g., 'eu-or-us').
- **tenantName** (string) - Required - The name of your tenant.
- **auth** (object) - Required - Authentication credentials. Refer to the Authentication Guide for details.
- **headers** (object) - Optional - Custom headers to be included in requests.
```
--------------------------------
### Run Development Server
Source: https://docs.corti.ai/assistant/guides/react-integration
Use this command to start the development server and view the integration.
```bash
npm run dev
```
--------------------------------
### Python Request Example
Source: https://docs.corti.ai/coding/encounter-coding
Example of how to make a request to the encounter coding API using Python. Ensure you have the necessary libraries installed.
```python
import os
from dotenv import load_dotenv
from corti_api.client import CortiAPI
load_dotenv()
api = CortiAPI(
tenant=os.environ["TENANT"],
environment=os.environ["ENVIRONMENT"],
token=os.environ["TOKEN"],
)
response = api.coding.encounter_coding(
encounter_id="a1b2c3d4-e5f6-7890-1234-567890abcdef",
patient_id="a1b2c3d4-e5f6-7890-1234-567890abcdef",
encounter_type="inpatient",
encounter_start_date="2023-01-01T00:00:00Z",
encounter_end_date="2023-01-01T00:00:00Z",
transcription=open("transcription.txt", "r").read(),
)
print(response.json())
```
--------------------------------
### Get Text Selection Start
Source: https://docs.corti.ai/sdk/dictation/overview
Retrieves the starting index of the current text selection in a textarea. Defaults to 0 if no selection is present.
```javascript
const start = textarea.selectionStart ?? 0;
```
--------------------------------
### C# .NET Configuration Example
Source: https://docs.corti.ai/sdk/overview
This C# example demonstrates how to set up the Corti client. Remember to replace the placeholder values for CLIENT_ID and CLIENT_SECRET with your actual credentials.
```csharp
using Corti;
// Replace these with your values
const string CLIENT_ID = "YOUR_CLIENT_ID";
const string CLIENT_SECRET = "YOUR_CLIENT_SECRET";
var client = new CortiClient(new CortiClientOptions
{
Environment = CortiEnvironment.Production,
TenantName = "YOUR_TENANT_NAME",
Auth = new CortiClientAuthOptions
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
}
});
```
--------------------------------
### Python: Example Usage
Source: https://docs.corti.ai/authentication/quickstart
This Python code shows an example of how to use the obtained access token. It defines a function to get the token and then prints it.
```python
def get_access_token():
# ... (code to get token as shown above)
pass
if __name__ == "__main__":
token = get_access_token()
print(f"Access token: {token}")
```
--------------------------------
### Initialize CortiClient in .NET
Source: https://docs.corti.ai/sdk/dotnet/overview
Demonstrates how to initialize the CortiClient with tenant, environment, and client secret. Ensure you have the necessary credentials before use.
```csharp
const string CLIENT_SECRET = "";
const string ENVIRONMENT = ""
const string TENANT = "";
var client = new CortiClient(
tenantName: TENANT,
environment: ENVIRONMENT,
```
--------------------------------
### Stream Configuration Example
Source: https://docs.corti.ai/api-reference/streams
Demonstrates how to initialize a new stream configuration, setting participant details and mode.
```javascript
const config = {
participants: new List(),
mode: new StreamConfigMode.Multiple
};
config.participants.push(new StreamConfigParticipant(
Channel.Audio,
StreamConfigParticipantRole.Multiple
));
config.mode = new StreamConfigMode.Multiple;
config.type =
```
--------------------------------
### Making a GET Request for Templates
Source: https://docs.corti.ai/textgen/templates
Demonstrates how to make a GET request to fetch templates. This example uses the previously defined URL and headers.
```python
# Default templates (en)
response = requests.get(url, headers=headers)
```
--------------------------------
### Get Selection Start and End
Source: https://docs.corti.ai/sdk/dictation/overview
Retrieves the start and end positions of the current text selection in a textarea. Defaults to 0 if no selection is present.
```javascript
const start = textarea.selectionStart ?? 0;
const end = textarea.selectionEnd ?? 0;
textarea.value = start !== end ? textarea.value
```
--------------------------------
### C# .NET Authentication Setup
Source: https://docs.corti.ai/api-reference/streams
Demonstrates how to set up CortiClient with authentication using an access token. Replace placeholder values with your actual credentials.
```csharp
using Corti;
// Replace these with your values
const string ACCESS_TOKEN = "";
var client = new CortiClient(
auth: CortiClientAuth.Bearer(accessToken: ACCESS_TOKEN)
);
```
--------------------------------
### Initialize CortiClient with PKCE Flow
Source: https://docs.corti.ai/sdk/dotnet/authentication
Instantiate the CortiClient using the PKCE authentication flow. Ensure you provide your tenant name, environment, client ID, the code obtained from the callback, and the redirect URI.
```csharp
new CortiClient(
tenantName: "",
environment: "",
auth: CortiClientAuth.Pkce(
clientId: "",
code: codeFromCallback,
redirectUri: "https://your-app.com/callback",
codeVerifier: codeVerifier
)
)
```
--------------------------------
### Corti JS SDK Authentication Example
Source: https://docs.corti.ai/assistant/authentication
This example demonstrates how to use the Corti JavaScript SDK for authentication. Ensure you have the SDK installed and imported correctly.
```javascript
import { CortiAuth, CortiClient, CortiEnvironment } from "@corti/sdk"
```
--------------------------------
### Example Recording Started Event
Source: https://docs.corti.ai/assistant/events/generated/recording/started
An example JSON payload for the recording.started event. This demonstrates the structure and typical values for interaction metadata and extracted facts.
```json
{
"id": "64c70610-3777-4331-802c-717187133660",
"title": "New patient registration",
"state": "inProgress",
"startedAt": "2023-01-01T10:00:00Z",
"transcriptCount": 1,
"documentCount": 0,
"facts": [
{
"id": "f_12345",
"text": "Patient name: John Doe",
"group": "Patient Information",
"source": "core",
"isDiscarded": false
}
]
}
```
--------------------------------
### Initialize CortiClient with Options
Source: https://docs.corti.ai/sdk/js/overview
Demonstrates how to initialize the CortiClient with various configuration options, including authentication, logging level, and a custom logger.
```javascript
const client = new CortiClient({
auth: {
// ... auth options
},
logging: {
level: LogLevel.Debug,
logger: new ConsoleLogger(),
},
silent: false, // defaults to true, set to false to enable logging
});
```
--------------------------------
### Example Recording Started Event
Source: https://docs.corti.ai/assistant/events/generated/recording/started
An example JSON object representing a recording.started event. This shows the typical structure and values for a new recording session.
```json
{
"event": "recording.started",
"confidential": false,
"payload": {
"mode": "virtual",
"language": "en-US",
"deviceLabel": "Built-in Microphone (Realtek High Definition Audio)",
"interactionId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"interactionState": "active"
}
}
```
--------------------------------
### CustomAuthClient Example
Source: https://docs.corti.ai/sdk/dotnet/reference
Demonstrates how to set up a standalone authentication client using client ID and secret. Replace placeholder values with your actual credentials.
```csharp
using Cort;
// Replace these with your values
const string CLIENT_ID = "";
const string CLIENT_SECRET = ""
```
--------------------------------
### Upload Recording with Options
Source: https://docs.corti.ai/sdk/js/overview
This example shows how to upload a recording with additional options. The SDK handles the asynchronous nature of the upload process.
```javascript
await client.recordings.upload("", "
");
```
--------------------------------
### Setting Up the Corti AI Client
Source: https://docs.corti.ai/sdk/dotnet/overview
Demonstrates how to initialize the Corti AI client with necessary configurations. Ensure you have your API key and endpoint ready.
```csharp
var client = new CortiAIClient("YOUR_API_KEY", "YOUR_ENDPOINT");
```
--------------------------------
### Real-time Transcription Example
Source: https://docs.corti.ai/sdk/dotnet/reference
Example of how to initiate real-time speech-to-text transcription using the Corti AI SDK. This snippet shows the basic setup for a transcription client.
```csharp
var transcribe = new Corti.Ai.Client.Transcription.TranscriptionClient(new Corti.Ai.Client.Configuration.ClientConfiguration
{
ApiKey = "YOUR_API_KEY",
WebSocketUri = new Uri("wss://api.corti.ai/v2/transcribe")
});
transcribe.OnMessage += (sender, e) =>
{
Console.WriteLine($"Received message: {e.Message}");
};
await transcribe.ConnectAsync();
// Send audio data here
// await transcribe.SendAsync(audioBytes);
// await Task.Delay(TimeSpan.FromSeconds(10)); // Simulate sending audio for 10 seconds
// await transcribe.CloseAsync();
```
--------------------------------
### JavaScript Authentication Example
Source: https://docs.corti.ai/api-reference/transcribe
Demonstrates how to set up authentication with an access token in JavaScript. Ensure you replace 'ACCESS_TOKEN' with your actual token.
```javascript
import { CortiClient, CortiClientAuth } from "@corti/client";
const auth = new CortiClientAuth(
{
accessToken: "ACCESS_TOKEN",
}
);
const client = new CortiClient(auth);
```
--------------------------------
### JavaScript SDK Example
Source: https://docs.corti.ai/sdk/overview
This example demonstrates how to set up the JavaScript SDK for Node.js or browser environments. It includes common headers for API requests.
```javascript
const { CortiClient } = require("@corti/sdk");
const client = new CortiClient({
// Use environment variables for sensitive information
// See: https://docs.corti.app/sdk/overview#environment-variables
environment: process.env.ENVIRONMENT,
// Use a token obtained from the Corti developer portal
// See: https://docs.corti.app/sdk/overview#authentication
token: process.env.TOKEN,
// Use a tenant name obtained from the Corti developer portal
// See: https://docs.corti.app/sdk/overview#authentication
tenant: process.env.TENANT
});
// Example of how to use the client
async function example() {
const interactions = await client.interactions.list();
console.log(interactions);
}
example();
```
--------------------------------
### JavaScript: Get Sentence Start and End Indices
Source: https://docs.corti.ai/sdk/dictation/overview
Calculates the start and end indices for sentences within a given text. This is useful for highlighting or manipulating specific sentence segments.
```javascript
const start = sentences.length > 0 ? sentences.length - 1 : 0;
const end = sentences.length;
textarea.focus();
textarea.setSelectionRange(start, end);
```
--------------------------------
### Python: Basic API Request Setup
Source: https://docs.corti.ai/get_started/encounter-coding
Sets up environment variables and imports the requests library for making API calls. Replace placeholder values with your actual credentials.
```python
import requests
# Replace these with your values
ENVIRONMENT = ""
TENANT = ""
API_KEY = ""
```
--------------------------------
### Start Express.js Server
Source: https://docs.corti.ai/assistant/authentication
This code snippet shows how to start an Express.js server and log a message to the console indicating the server is running. It's a basic setup for a web server.
```javascript
const app = require('./app');
app.listen(3000, () => {
console.log("Server running at http://localhost:3000");
});
```
--------------------------------
### Initialize CortiClient with Logging
Source: https://docs.corti.ai/sdk/js/overview
Demonstrates how to import and initialize the CortiClient with custom logging configurations. Ensure the '@corti/sdk' package is installed.
```typescript
import { CortiClient, logging } from "@corti/sdk";
const client = new CortiClient({
logging: {
level: "debug",
destination: "console"
}
});
```
--------------------------------
### Basic SDK Usage Example
Source: https://docs.corti.ai/sdk/dotnet/overview
Demonstrates basic usage of the Corti AI SDK, including setting up the client and making a request. Ensure you have the necessary using statements.
```csharp
using Corti.AI.Client;
var client = new CortiAIClient("YOUR_API_KEY");
var response = await client.SendRequestAsync(new RequestOptions
{
Prompt = "What is the capital of France?",
Model = "text-davinci-003",
MaxTokens = 50
});
Console.WriteLine(response.Choices[0].Text);
```
--------------------------------
### Get Transcript Example
Source: https://docs.corti.ai/sdk/js/reference
Fetch a single transcript by providing the interaction ID and the transcript ID.
```typescript
get(interactionId, transcriptId)
```
--------------------------------
### Initialize CortiClient with Authentication Details
Source: https://docs.corti.ai/sdk/dotnet/authentication
Instantiate the CortiClient by providing your unique CLIENT_ID, CLIENT_SECRET, ENVIRONMENT, and TENANT. Ensure these values are correctly set before initializing the client.
```csharp
const string CLIENT_ID = "";
const string CLIENT_SECRET = "";
const string ENVIRONMENT = "";
const string TENANT = "";
var client = new CortiClient(
```
--------------------------------
### Get WebSocket Token
Source: https://docs.corti.ai/sdk/dotnet/authentication
Retrieve a token with WebSocket scopes. This example demonstrates obtaining a token for real-time communication.
```javascript
var webSocketToken = await auth.GetTokenAsync(
new OAuthTokenRequestWithScopes
{
ClientId = "",
ClientSecret = "",
Scopes = ["websocket"]
});
```
--------------------------------
### Get Access Token
Source: https://docs.corti.ai/llms-full.txt
This section provides code examples for obtaining an OAuth2 client-credentials access token from Corti.
```APIDOC
## Get Access Token
This section provides code examples for obtaining an OAuth2 client-credentials access token from Corti.
### C# .NET
```csharp
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
public class AuthExample
{
private const string CLIENT_ID = "";
private const string CLIENT_SECRET = "";
private const string ENVIRONMENT = "";
private const string TENANT = "";
static async Task GetAccessTokenAsync()
{
var tokenUrl = $"https://auth.{ENVIRONMENT}.corti.app/realms/{TENANT}/protocol/openid-connect/token";
using var http = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair("client_id", CLIENT_ID),
new KeyValuePair("client_secret", CLIENT_SECRET),
new KeyValuePair("grant_type", "client_credentials"),
new KeyValuePair("scope", "openid")
});
var response = await http.PostAsync(tokenUrl, content);
response.EnsureSuccessStatusCode();
var payload = await response.Content.ReadAsStringAsync();
using var json = JsonDocument.Parse(payload);
return json.RootElement.GetProperty("access_token").GetString()!;
}
static async Task Main()
{
var token = await GetAccessTokenAsync();
Console.WriteLine($"Access token: {token}");
}
}
```
### Python
```python
import requests
# Replace these with your values
CLIENT_ID = ""
CLIENT_SECRET = ""
ENVIRONMENT = ""
TENANT = ""
def get_access_token():
"""Request an OAuth2 client-credentials access token from Corti."""
url = f"https://auth.{ENVIRONMENT}.corti.app/realms/{TENANT}/protocol/openid-connect/token"
data = {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"grant_type": "client_credentials",
"scope": "openid",
}
res = requests.post(url, data=data, headers={"Content-Type": "application/x-www-form-urlencoded"})
res.raise_for_status()
return res.json()["access_token"]
# Example usage
if __name__ == "__main__":
token = get_access_token()
print("Access token:", token)
```
### cURL
```bash
# Replace these with your values
CLIENT_ID=""
CLIENT_SECRET=""
ENVIRONMENT=""
TENANT=""
curl "https://auth.${ENVIRONMENT}.corti.app/realms/${TENANT}/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" \
-d "grant_type=client_credentials" \
-d "scope=openid"
```
```
--------------------------------
### Example Stream Configuration
Source: https://docs.corti.ai/api-reference/streams
This example shows a typical configuration for creating a stream, including settings for diarization, multichannel audio, participant identification, and output format.
```json
{
"isDiarization": false,
"isMultichannel": false,
"participants": [
{
"channel": 0,
"role": "multiple"
}
],
"mode": {
"type": "facts",
"outputLocale": "en"
},
"xCortiRetentionPolicy": "retain"
}
```
--------------------------------
### Initialize WebSocket Proxy
Source: https://docs.corti.ai/sdk/js/proxy
Example of initializing the WebSocket proxy with a URL. This is the basic setup required to establish a connection.
```javascript
const socket = new WebSocketProxy("wss://your-proxy-url.com");
```
--------------------------------
### CortiClient Initialization
Source: https://docs.corti.ai/sdk/dotnet/reference
Shows how to initialize the CortiClient with a configured environment.
```APIDOC
## CortiClient Initialization
### Description
Initializes the CortiClient using a previously configured environment.
### Method Signature
```csharp
var client = new CortiClient(environment);
```
### Parameters
- **environment** (CortiEnvironments) - The configured environment object.
```
--------------------------------
### Create Interaction URL
Source: https://docs.corti.ai/llms-full.txt
Example URL for creating an interaction on the EU environment. This serves as the starting point for other workflow operations.
```bash
POST https://api.eu.corti.app/v2/interactions/
```
--------------------------------
### Initialize CortiClient in C#
Source: https://docs.corti.ai/sdk/dotnet/overview
Instantiate the CortiClient with your tenant, environment, and authentication details. Ensure you replace placeholder values with your actual credentials.
```csharp
var client = new CortiClient(
tenantName: "YOUR_TENANT",
environment: "YOUR_ENVIRONMENT_ID",
auth: CortiClientAuth.ClientCredentials(
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
),
```