Skip to main content
AssemblyAI is an applied AI company that offers AI models for audio transcription, content moderation, summarization, topic detection, and many other tasks. In this guide, we will show you how to call and log AssemblyAI speech-to-text model with Respan gateway and log LLM calls.

Prerequisites

  • A Respan account.
  • A Respan API key.
  • An AssemblyAI account.
  • An AssemblyAI API key.

Quickstart

Here’s an example of how to call and log AssemblyAI speech-to-text model with Respan gateway. The API endpoint for this integration is https://api.respan.ai/api/assemblyai/.
Python
import os
from assemblyai import (
    Transcriber,
    Client,
    Settings,
    TranscriptStatus,
)
from base64 import b64encode
import json

API_KEY = os.getenv("RESPAN_API_KEY")
BASE_URL = (
    os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/") + "api/assemblyai/"
)


class RespanAssemblyAIClient(Client):
    """
    Define Respan's AssemblyAI client wrapper for passing extra headers containing respan params
    """

    def __init__(self, respan_api_key: str, headers: dict):
        settings = Settings(api_key=respan_api_key, base_url=BASE_URL)
        print(settings)
        super().__init__(settings=settings)
        self._http_client.headers.update(headers)

respan_params = {
    "metadata": {
        "paid_user": "true",
    }
    # other respan parameters...
}

respan_headers = {
    "X-Assemblyai-Api-Key": os.getenv("ASSEMBLYAI_API_KEY"), # <-- This is the AssemblyAI API key
    "X-Data-Respan-Params": b64encode(
        json.dumps(respan_params).encode()
    ).decode(),
}

client = RespanAssemblyAIClient(
    respan_api_key=API_KEY, # <-- This is the API key for authenticating against Respan, not the AssemblyAI API key (defined above)
    headers=respan_headers
)

transcriber = Transcriber(client=client)

transcript = transcriber.transcribe("https://assembly.ai/wildfires.mp3")

if transcript.status == TranscriptStatus.error:
    print(transcript.error)
else:
    print(transcript.text)

Respan params

You can pass any Respan observability parameters in the metadata field.