> ## Documentation Index
> Fetch the complete documentation index at: https://docs.profy.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Complete your first Profy API call in 5 minutes

This guide will walk you through making your first Profy API call in 5 minutes.

## Prerequisites

* A Profy account (register at [app.profy.cn](https://app.profy.cn))
* Python 3.8+ or Node.js 18+ (if using the SDK)

## Step 1: Get an API Key

1. Log in at [app.profy.cn](https://app.profy.cn)
2. Visit [platform.profy.cn](https://platform.profy.cn) (shares login session with the main site)
3. Go to the **API Keys** page
4. Click **Create API Key**, enter a name, and select permission scopes
5. Copy the generated key (prefixed with `sk-pro-`)

<Warning>
  The API Key is displayed only once at creation time. Save it immediately in a secure location. If lost, you will need to create a new one.
</Warning>

## Step 2: Make Your First Call

Choose your preferred method:

<Tabs>
  <Tab title="Python SDK">
    Install the SDK:

    ```bash theme={null}
    pip install profy
    ```

    Call an Expert:

    ```python theme={null}
    import asyncio
    from profy import Profy

    async def main():
        async with Profy(api_key="sk-pro-your-key-here") as client:
            # Call an Expert
            result = await client.agents.run(
                "profy",        # Expert identifier
                "用一句话介绍你自己"  # Message content
            )
            print(result.text)
            print(f"Model: {result.model}")
            print(f"Elapsed: {result.elapsed_sec}s")

    asyncio.run(main())
    ```

    If you prefer synchronous code:

    ```python theme={null}
    from profy import ProfySync

    with ProfySync(api_key="sk-pro-your-key-here") as client:
        result = client.agents.run("profy", "用一句话介绍你自己")
        print(result.text)
    ```
  </Tab>

  <Tab title="TypeScript SDK">
    Install the SDK:

    ```bash theme={null}
    npm install @profy-ai/sdk
    ```

    Call an Expert:

    ```typescript theme={null}
    import { Profy } from "@profy-ai/sdk";

    const client = new Profy({ apiKey: "sk-pro-your-key-here" });

    const result = await client.agents.run(
      "profy",        // Expert identifier
      "用一句话介绍你自己"  // Message content
    );

    console.log(result.text);
    console.log(`Model: ${result.model}`);
    console.log(`Elapsed: ${result.elapsedMs}ms`);
    ```
  </Tab>

  <Tab title="curl">
    ```bash theme={null}
    curl -X POST https://api.profy.cn/v1/agents/run \
      -H "Authorization: Bearer sk-pro-your-key-here" \
      -H "Content-Type: application/json" \
      -d '{
        "expert_identifier": "profy",
        "message": "用一句话介绍你自己"
      }'
    ```

    The response is an SSE (Server-Sent Events) stream:

    ```
    event: run.created
    data: {"type":"run.created","event_id":1}

    event: run.in_progress
    data: {"type":"run.in_progress","model_name":"deepseek-v3","session_id":"abc123","event_id":2}

    event: output.text.delta
    data: {"type":"output.text.delta","delta":"你好","event_id":3}

    event: output.text.delta
    data: {"type":"output.text.delta","delta":"！我是","event_id":4}

    event: run.completed
    data: {"type":"run.completed","event_id":5}

    data: [DONE]
    ```
  </Tab>
</Tabs>

## Step 3: Stream Responses

For scenarios that require real-time display of AI output, use streaming mode:

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from profy import Profy

  async def main():
      async with Profy(api_key="sk-pro-your-key-here") as client:
          async for chunk in client.agents.run_stream("profy", "写一首关于编程的诗"):
              if chunk.type == "output.text.delta":
                  print(chunk.delta, end="", flush=True)
              elif chunk.type == "tool_call.created":
                  print(f"\n[Tool call: {chunk.raw.get('tool_name')}]")
              elif chunk.type == "run.completed":
                  print("\n[Done]")

  asyncio.run(main())
  ```

  ```typescript TypeScript theme={null}
  import { Profy } from "@profy-ai/sdk";

  const client = new Profy({ apiKey: "sk-pro-your-key-here" });

  for await (const chunk of client.agents.runStream("profy", "写一首关于编程的诗")) {
    if (chunk.type === "output.text.delta") {
      process.stdout.write(chunk.delta ?? "");
    } else if (chunk.type === "tool_call.created") {
      console.log(`\n[Tool call: ${chunk.toolName}]`);
    } else if (chunk.type === "run.completed") {
      console.log("\n[Done]");
    }
  }
  ```
</CodeGroup>

## Step 4: Multi-Turn Conversations

Pass a `session_id` to continue the same conversation:

<CodeGroup>
  ```python Python theme={null}
  async with Profy(api_key="sk-pro-your-key-here") as client:
      # First turn
      r1 = await client.agents.run("profy", "我叫小明")
      print(r1.text)
      session_id = r1.session_id

      # Second turn — the Expert remembers your name
      r2 = await client.agents.run(
          "profy", "你还记得我叫什么吗？",
          session_id=session_id
      )
      print(r2.text)
  ```

  ```typescript TypeScript theme={null}
  const client = new Profy({ apiKey: "sk-pro-your-key-here" });

  // First turn
  const r1 = await client.agents.run("profy", "我叫小明");
  console.log(r1.text);

  // Second turn — the Expert remembers your name
  const r2 = await client.agents.run("profy", "你还记得我叫什么吗？", {
    sessionId: r1.sessionId,
  });
  console.log(r2.text);
  ```
</CodeGroup>

## Understanding SSE Events

`/v1/agents/run` returns a standard SSE event stream. Here are the core event types you will encounter:

| Event                 | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `run.created`         | Request received; processing started                                  |
| `run.in_progress`     | Agent started running; includes `model_name` and `session_id`         |
| `output.text.delta`   | Incremental text output; `delta` field contains the new text fragment |
| `tool_call.created`   | Agent started calling a tool                                          |
| `tool_call.completed` | Tool call completed                                                   |
| `run.completed`       | Agent run completed                                                   |
| `run.failed`          | Run failed; `message` field contains the error details                |

For the full event type list, see [Agents Run API](/en/developers/api/agents-run#sse-event-types).

## Using Chat Completions

If you are already using the OpenAI API, you can switch directly to Profy's compatible endpoint:

<Tabs>
  <Tab title="Call a raw model">
    <CodeGroup>
      ```python Python theme={null}
      async with Profy(api_key="sk-pro-your-key-here") as client:
          resp = await client.chat.completions.create(
              model="deepseek-v3",
              messages=[{"role": "user", "content": "Hello"}],
          )
          print(resp.text)
      ```

      ```typescript TypeScript theme={null}
      const client = new Profy({ apiKey: "sk-pro-your-key-here" });

      const resp = await client.chat.completions.create({
        model: "deepseek-v3",
        messages: [{ role: "user", content: "Hello" }],
      });
      console.log(resp.text);
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Call an Expert via OpenAI SDK">
    Use the `profy-<identifier>` model name format to call a Profy Expert directly with the standard OpenAI SDK:

    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="sk-pro-your-key-here",
        base_url="https://api.profy.cn/v1",
    )

    response = client.chat.completions.create(
        model="profy-financial-advisor",
        messages=[{"role": "user", "content": "Analyze Tesla's investment value"}],
        stream=True,
    )

    for chunk in response:
        if chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication Guide" icon="lock" href="/en/developers/authentication">
    Learn more about API Key and OAuth usage
  </Card>

  <Card title="Agents Run API" icon="robot" href="/en/developers/api/agents-run">
    View the complete Expert invocation API documentation
  </Card>

  <Card title="Python SDK" icon="python" href="/en/developers/sdk-python">
    Complete Python SDK guide
  </Card>

  <Card title="TypeScript SDK" icon="js" href="/en/developers/sdk-typescript">
    Complete TypeScript SDK guide
  </Card>
</CardGroup>
