# Developer API quickstart

URL: https://docs.assistantcore.com/en/developers/quickstart

Create an API key and get your first assistant response from the Developer API in about five minutes.

This tutorial takes you from no key to a first chat response, then continues the same conversation. Run it from a terminal or a backend, never from a browser console.

## Before you begin [#before-you-begin]

- You are the **Assistant Owner**. Every plan can use the Developer API, Free included.
- The owner has [credits](/en/billing/credits) left; each response uses them.
- You have `curl`, Python 3.8+, or Node.js 18+.

## Create an API key [#create-an-api-key]

1. Open the [Admin Panel](https://admin.assistantcore.com) and select the assistant.
2. In the sidebar, select **Developer API**.
3. Select **Create API key**.
4. Enter a **Key name**, for example `Quickstart`, and under **Scopes** select only **Chat** (`chat:write`).
5. Select **Create API key**, then **Copy API key**, and select **I've saved the key**.

The key starts with `ac_` and is shown only once. If you lose it, rotate the key to get a replacement (see [API keys and security](/en/developers/api-keys-security)).

## Set environment variables [#set-environment-variables]

```bash
export ASSISTANT_API_URL="https://api.assistantcore.com"
export ASSISTANT_API_KEY="<your-api-key>"
export EXTERNAL_USER_ID="customer_42"
```

The **Developer API** page shows the base URL under **API base URL**. `external_user_id` is your own ID for the end user: 1–256 characters, stable for the same person, and free of emails, phone numbers, or secrets.

## Send your first request [#send-your-first-request]

<Tabs items={["curl","Python","JavaScript"]}>
<Tab value="curl">
```bash
curl "$ASSISTANT_API_URL/v1/responses" \
  --request POST \
  --header "Authorization: Bearer $ASSISTANT_API_KEY" \
  --header "Content-Type: application/json" \
  --header "Idempotency-Key: $(uuidgen)" \
  --data "{
    \"external_user_id\": \"$EXTERNAL_USER_ID\",
    \"input\": \"Summarize your return policy.\"
  }"
```
</Tab>

<Tab value="Python">
```python
import json
import os
import urllib.request
import uuid

request = urllib.request.Request(
    os.environ["ASSISTANT_API_URL"] + "/v1/responses",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["ASSISTANT_API_KEY"],
        "Content-Type": "application/json",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    data=json.dumps({
        "external_user_id": os.environ["EXTERNAL_USER_ID"],
        "input": "Summarize your return policy.",
    }).encode(),
)
with urllib.request.urlopen(request, timeout=120) as response:
    body = json.load(response)

print(body["output_text"])
print("conversation_id:", body["conversation_id"])
```
</Tab>

<Tab value="JavaScript">
```js
// Node.js 18+ (save as quickstart.mjs)
const response = await fetch(`${process.env.ASSISTANT_API_URL}/v1/responses`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASSISTANT_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    external_user_id: process.env.EXTERNAL_USER_ID,
    input: "Summarize your return policy.",
  }),
})

const body = await response.json()
if (!response.ok) throw new Error(`${body.code}: ${body.message}`)
console.log(body.output_text)
console.log("conversation_id:", body.conversation_id)
```
</Tab>
</Tabs>

A successful call returns `200`:

```json
{
  "id": "resp_5f0c2a9e8b7d4c1fa3e6b2d9c8a7f104",
  "object": "response",
  "status": "completed",
  "conversation_id": "a12d5e41-7ab7-4c8f-b024-c2c38b5c43f4",
  "model": "gemini-3.8-flash",
  "output_text": "Our return policy allows...",
  "message_id": "b0f16c77-a275-46c8-9dc8-8fe9fd5991cc",
  "request_id": "3f9a1c0b7d2e"
}
```

If you get an error instead, the body has a `code`. The most common ones on a first call:

| Code | Fix |
| :--- | :--- |
| `INVALID_API_KEY` | The key is missing, mistyped, or truncated. Copy it again or rotate it. |
| `INSUFFICIENT_SCOPE` | The key lacks `chat:write`. Create a key with the **Chat** scope. |
| `INSUFFICIENT_CREDITS` | The owner is out of credits. |

All codes are in [Errors and limits](/en/developers/errors-limits).

## Continue the conversation [#continue-the-conversation]

Send the `conversation_id` from the first response, the same `external_user_id`, and a new `Idempotency-Key`:

```bash
curl "$ASSISTANT_API_URL/v1/responses" \
  --request POST \
  --header "Authorization: Bearer $ASSISTANT_API_KEY" \
  --header "Content-Type: application/json" \
  --header "Idempotency-Key: $(uuidgen)" \
  --data "{
    \"external_user_id\": \"$EXTERNAL_USER_ID\",
    \"conversation_id\": \"<conversation-id>\",
    \"input\": \"Does that apply to sale items?\"
  }"
```

The assistant answers with the earlier turn in context. Another `external_user_id` gets `404 CONVERSATION_NOT_FOUND` for this conversation.

## Move the call into your backend [#move-the-call-into-your-backend]

In production, your backend makes the call and derives `external_user_id` from its own sign-in session. This Next.js route handler is one way to do it; replace `getAuthenticatedUserId()` with your auth helper.

```ts title="app/api/assistant/chat/route.ts"
export async function POST(request: Request) {
  const externalUserId = await getAuthenticatedUserId(request)
  if (!externalUserId) {
    return Response.json({ error: "Unauthorized" }, { status: 401 })
  }

  const { input, conversationId } = await request.json()
  const response = await fetch(`${process.env.ASSISTANT_API_URL}/v1/responses`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.ASSISTANT_API_KEY}`,
      "Content-Type": "application/json",
      "Idempotency-Key": crypto.randomUUID(),
    },
    body: JSON.stringify({
      external_user_id: externalUserId,
      conversation_id: conversationId,
      input,
    }),
  })

  return Response.json(await response.json(), { status: response.status })
}
```

Before going live:

- Grant each key only the scopes it needs, and use a separate assistant and key for staging (Preview has no sandbox; staging calls use real credits).
- Set an HTTP timeout and retry only when `retryable` is `true`, reusing the same `Idempotency-Key` for the same operation.
- Log `X-Request-ID` with the status code; never log the API key.

<Cards>
<Card title="Chat API" description="Stream with SSE, attach files, and read history." href="/en/developers/chat-api" />

<Card title="API keys and security" description="Expiry, IP allowlists, rotation, and revocation." href="/en/developers/api-keys-security" />

<Card title="Errors and limits" description="Error codes, retries, and rate limits." href="/en/developers/errors-limits" />
</Cards>