> For the complete documentation index, see [llms.txt](https://docs.amigo.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.amigo.ai/developer-guide/classic-api/sdks/sdk-hello-world.md).

# Hello World Example

This guide demonstrates creating your first conversation using the Amigo SDK in Python or TypeScript.

## Prerequisites

{% hint style="info" %}
**Before you begin.**

1. [**Installed the SDK**](/developer-guide/classic-api/sdks/sdk-installation.md) in your project.
2. [**Configured your credentials**](/developer-guide/classic-api/sdks/sdk-configuration.md) with valid API keys.
3. **Service ID** from your Amigo dashboard.
   {% endhint %}

## Quick Overview

```mermaid
%%{init: {"theme": "base", "themeVariables": {"actorBkg": "#083241", "actorTextColor": "#FFFFFF", "actorBorder": "#083241", "signalColor": "#575452", "signalTextColor": "#100F0F", "labelBoxBkgColor": "#F1EAE7", "labelBoxBorderColor": "#D7D2D0", "labelTextColor": "#100F0F", "loopTextColor": "#100F0F", "noteBkgColor": "#F1EAE7", "noteBorderColor": "#D7D2D0", "noteTextColor": "#100F0F", "activationBkgColor": "#E8E2EB", "activationBorderColor": "#083241", "altSectionBkgColor": "#F1EAE7", "altSectionColor": "#100F0F"}}}%%
sequenceDiagram
    autonumber
    participant App as Your Application
    participant SDK as Amigo SDK
    participant API as Amigo API

    Note over App,API: Step 1: Create Conversation
    App->>SDK: createConversation(service_id)
    SDK->>API: POST /conversation
    API-->>SDK: conversation-created event
    SDK-->>App: conversation_id

    Note over App,API: Step 2: Send Message
    App->>SDK: interact("Hello!")
    SDK->>API: POST /interact
    API-->>SDK: streaming NDJSON events
    SDK-->>App: new-message events

    Note over App,API: Step 3: Finish
    App->>SDK: finish(conversation_id)
    SDK->>API: POST /finish
    API-->>SDK: 204 No Content
```

## Code Examples

{% tabs %}
{% tab title="Python" %}
Here's a complete example that creates a conversation, sends a message, and handles the streaming response:

```python
from amigo_sdk import AmigoClient
from amigo_sdk.models import (
    ConversationCreateConversationRequest,
    CreateConversationParametersQuery,
    InteractWithConversationParametersQuery,
)

def hello_world():
    # Initialize the client
    with AmigoClient(
        api_key="your-api-key",
        api_key_id="your-api-key-id",
        user_id="your-user-id",
        organization_id="your-org-id"
    ) as client:

        # Step 1: Create a conversation
        print("Creating conversation...")
        create_events = client.conversations.create_conversation(
            ConversationCreateConversationRequest(
                service_id="your-service-id",
                service_version_set_name="release"
            ),
            CreateConversationParametersQuery(response_format="text")
        )

        # Process creation events
        conversation_id = None
        for event in create_events:
            event_data = event.model_dump(mode="json")
            print(f"Create event: {event_data.get('type')}")

            if event_data.get("type") == "conversation-created":
                conversation_id = event_data.get("conversation_id")
                print(f"Conversation created: {conversation_id}")

            if event_data.get("type") == "interaction-complete":
                break

        if not conversation_id:
            raise RuntimeError("Failed to create conversation")

        # Step 2: Send a message
        print("\nSending message...")
        interaction_events = client.conversations.interact_with_conversation(
            conversation_id,
            InteractWithConversationParametersQuery(
                request_format="text",
                response_format="text"
            ),
            text_message="Hello! Can you help me get started with Amigo?"
        )

        # Process interaction events
        full_response = ""
        for event in interaction_events:
            event_data = event.model_dump(mode="json")

            if event_data.get("type") == "new-message":
                message_chunk = event_data.get("message", "")
                full_response += message_chunk
                print(message_chunk, end="", flush=True)

            elif event_data.get("type") == "interaction-complete":
                print(f"\nResponse complete!")
                break

        print(f"\nFull response: {full_response}")

        # Step 3: Finish the conversation
        print("\nFinishing conversation...")
        try:
            client.conversations.finish_conversation(conversation_id)
            print("Conversation finished successfully!")
        except Exception as e:
            print(f"Warning: {e}")

if __name__ == "__main__":
    hello_world()
```

{% endtab %}

{% tab title="TypeScript" %}
Here's the equivalent example in TypeScript:

```typescript
import { AmigoClient } from "@amigo-ai/sdk";

async function helloWorld(): Promise<void> {
  // Initialize the client
  const client = new AmigoClient({
    apiKey: "your-api-key",
    apiKeyId: "your-api-key-id",
    userId: "your-user-id",
    orgId: "your-org-id",
  });

  try {
    // Step 1: Create a conversation
    console.log("Creating conversation...");
    const createEvents = await client.conversations.createConversation({
      body: {
        service_id: "your-service-id",
        service_version_set_name: "release",
      },
      query: { response_format: "text" },
    });

    // Process creation events
    let conversationId: string | undefined;
    for await (const event of createEvents) {
      console.log(`Create event: ${event.type}`);

      if (event.type === "conversation-created") {
        conversationId = event.conversation_id;
        console.log(`Conversation created: ${conversationId}`);
      }

      if (event.type === "interaction-complete") {
        break;
      }
    }

    if (!conversationId) {
      throw new Error("Failed to create conversation");
    }

    // Step 2: Send a message
    console.log("\nSending message...");
    const interactionEvents =
      await client.conversations.interactWithConversation({
        conversationId,
        input: "Hello! Can you help me get started with Amigo?",
        query: { request_format: "text", response_format: "text" },
      });

    // Process interaction events
    let fullResponse = "";
    for await (const event of interactionEvents) {
      if (event.type === "new-message") {
        const messageChunk = event.message || "";
        fullResponse += messageChunk;
        process.stdout.write(messageChunk);
      } else if (event.type === "interaction-complete") {
        console.log("\nResponse complete!");
        break;
      }
    }

    console.log(`\nFull response: ${fullResponse}`);

    // Step 3: Finish the conversation
    console.log("\nFinishing conversation...");
    try {
      await client.conversations.finishConversation({ conversationId });
      console.log("Conversation finished successfully!");
    } catch (error) {
      console.log(`Warning: ${error}`);
    }
  } catch (error) {
    console.error("Error:", error);
    process.exit(1);
  }
}

// Run the example
helloWorld();
```

{% endtab %}
{% endtabs %}

## Next Steps

Now that you've created your first conversation, explore:

* [**Error Handling**](/developer-guide/classic-api/sdks/sdk-error-handling.md)**.** Handle errors and edge cases properly.
* [**Conversations: Create**](/developer-guide/classic-api/core-api/conversations/conversations-create.md)**.** Agent-first, user-first, and external-event patterns.
* [**Conversations: Interact**](/developer-guide/classic-api/core-api/conversations/conversations-interact.md)**.** Streaming responses and event handlers.
* [**User Management**](/developer-guide/classic-api/core-api/users.md)**.** Managing users with the SDK.


---

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

```
GET https://docs.amigo.ai/developer-guide/classic-api/sdks/sdk-hello-world.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.
