UnieAI Studio

Call an agent from code, step by step

Verify the agent, Runtime URL, key, and model ID, send a request, and compare the answer.

Complete the document agent walkthrough and verify Playground first. This guide connects that agent to a backend. For uploading files from code, use the parsing tutorial.

1. Confirm project or personal account and key

  1. Select the agent's personal account or project.
  2. Open API Keys.
  3. Use a key allowed to call the agent, or create an application key.
  4. If a model allowlist is configured, include this agent.
 Locate the system Default Key.  Use its copy action to obtain the full secret; screenshots keep secrets masked.
Locate the system Default Key. Use its copy action to obtain the full secret; screenshots keep secrets masked. Click to enlarge

2. Copy the agent model ID and Runtime URL

  1. Open Agent Builder → My Agents → your agent → Setup.
  2. Find Call this agent and copy Model ID.
  3. Inspect its API samples for the public Runtime Base URL.
  4. Do not infer the ID from a display name or substitute the base-model name.
URLPurpose
Studio, such as https://studio.example.comWebsite and /api/parse/jobs
Runtime, such as https://api.example.com/v1/chat/completions, /v1/models, and model APIs

They can differ unless the deployment exposes both through one gateway. Use the agent's actual connection information.

 Copy the agent model ID.  Open Playground and verify this agent is selected.
Copy the agent model ID. Open Playground and verify this agent is selected. Click to enlarge

3. Set environment variables

export UNIEAI_RUNTIME_URL="https://api.example.com"
export UNIEAI_API_KEY="YOUR_API_KEY"
export UNIEAI_AGENT_MODEL="YOUR_AGENT_MODEL_ID"

Replace every placeholder. The next example requires cURL, not an OpenAI SDK.

4. Send the first request

curl --fail-with-body -sS \
  "$UNIEAI_RUNTIME_URL/v1/chat/completions" \
  -H "Authorization: Bearer $UNIEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$UNIEAI_AGENT_MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"What are ORBIT-42 support hours and timezone? Cite the source.\"}],\"stream\":false}"

Success is HTTP 200; read choices[0].message.content. Other fields depend on the model and engine. Validate a non-streaming request first before implementing streaming.

Checkpoint: with the sample, the answer contains Monday–Friday, 09:00–18:00, Asia/Taipei, and the source filename.

5. Call the same agent with Python

python -m pip install requests
import os
import requests

response = requests.post(
    os.environ["UNIEAI_RUNTIME_URL"].rstrip("/") + "/v1/chat/completions",
    headers={"Authorization": f"Bearer {os.environ['UNIEAI_API_KEY']}"},
    json={
        "model": os.environ["UNIEAI_AGENT_MODEL"],
        "messages": [{"role": "user", "content": "What are ORBIT-42 support hours? Cite the source."}],
        "stream": False,
    },
    timeout=(10, 180),
)
if not response.ok:
    raise RuntimeError(f"HTTP {response.status_code}: {response.text}")
print(response.json()["choices"][0]["message"]["content"])

6. Compare and diagnose

  1. Ask the same question as in Playground.
  2. Compare agent model ID, key scope, conversation history, and generation parameters.
  3. Find the request in Usage or the agent's Request Logs.
  4. Record the error and request ID, not only a screenshot of an empty answer.
SymptomFirst action
404 or HTMLCheck for a Studio URL where Runtime is needed
401/403Check key, project or personal account, agent access, model restrictions
Answer ignores documentsAgent ID, attached KB, tool engine
TimeoutInspect request logs and tools; choose an appropriate client waiting limit

Next: API reference, KB parsing, and acceptance checks.