# Team API Access How workspace context is resolved in API requests, and how access controls protect cross-context operations. ## Context Resolution Every authenticated API request resolves to a workspace context — either **personal** or a specific **team**. The context is determined **automatically** by the project's assignment: - If the project belongs to a team → team context is activated - If the project is personal → personal context is activated You do not need to send any additional headers. The API key carries the context implicitly. ```bash # This project is assigned to a team — team context is automatic curl -X POST "https://api.wiro.ai/v1/Run/google/nano-banana" \ -H "x-api-key: YOUR_TEAM_PROJECT_API_KEY" \ -d '{"prompt": "Hello"}' ``` ```bash # This project is personal — personal context is automatic curl -X POST "https://api.wiro.ai/v1/Run/google/nano-banana" \ -H "x-api-key: YOUR_PERSONAL_API_KEY" \ -d '{"prompt": "Hello"}' ``` Create a project inside a team to get a team API key, or use a personal project for personal context. The same `x-api-key` header works for both — no extra configuration needed. ## What Gets Filtered by Context When a workspace context is active, all list and query endpoints return only resources belonging to that context: | Endpoint | Personal context returns | Team context returns | |----------|------------------------|---------------------| | `Project/List` | Personal projects only | Team projects only | | `UserAgent/MyAgents` | Personal agents only | Team agents only | | `Task/List` | Personal tasks only | Team tasks only | | `Task/Stat` | Personal task statistics | Team task statistics | | `Project/UsageSummary` | Personal project usage | Team project usage | | `Wallet/List` | Personal wallet | Team wallet | | `Wallet/TransactionList` | Personal transactions | Team transactions | | `Coupon/UserList` | Personal coupons | Team coupons | ## Agent Context Guards Wiro enforces strict context isolation for agent operations. When you interact with an agent, your current workspace context must match the agent's workspace: | Your context | Agent's workspace | Result | |-------------|-------------------|--------| | Personal | Personal | Allowed | | Team A | Team A | Allowed | | Personal | Team A | **Blocked** | | Team A | Personal | **Blocked** | | Team A | Team B | **Blocked** | ### Protected Endpoints The following agent endpoints enforce context guards: - `UserAgent/Message/Send` — send a message to an agent - `UserAgent/Message/History` — view conversation history - `UserAgent/Message/Sessions` — list conversation sessions - `UserAgent/Message/Delete` — delete a conversation - `UserAgent/Deploy` — deploy a new agent (team context must match) - `UserAgent/CreateExtraCreditCheckout` — purchase extra credits - `UserAgent/CancelSubscription` — cancel subscription - `UserAgent/RenewSubscription` — renew subscription - `UserAgent/UpgradePlan` — upgrade plan ### Error Response When a context mismatch is detected: ```json { "result": false, "errors": [ { "code": 0, "message": "This agent belongs to a team. Switch to the team context to access it." } ] } ``` Or for the reverse case: ```json { "result": false, "errors": [ { "code": 0, "message": "This agent is personal. Switch to your personal context to access it." } ] } ``` ## Practical Examples ### Running a Model with a Team Project Create a project inside a team, then use its API key. The team context is resolved automatically: ```bash # 1. Create a project in team context (from dashboard or API) # 2. Use the project's API key — billing goes to team wallet curl -X POST "https://api.wiro.ai/v1/Run/stability-ai/sdxl" \ -H "x-api-key: YOUR_TEAM_PROJECT_API_KEY" \ -d '{"prompt": "A mountain landscape"}' ``` The task is created with the team's `teamguid`. The cost is deducted from the team wallet. The task appears in the team's usage statistics. ### Listing Team Agents with API Key Use a team project API key to list agents deployed in the team: ```bash curl -X POST "https://api.wiro.ai/v1/UserAgent/MyAgents" \ -H "x-api-key: YOUR_TEAM_PROJECT_API_KEY" \ -d '{"limit": 10}' ``` This returns only agents with `teamguid` matching the project's team — personal agents are not included. ### Sending a Message to a Team Agent The API key must belong to the same team as the agent: ```bash # Works — team project + team agent in the same team curl -X POST "https://api.wiro.ai/v1/UserAgent/Message/Send" \ -H "x-api-key: YOUR_TEAM_PROJECT_API_KEY" \ -d '{"useragentguid": "agent-guid-here", "message": "Hello"}' ``` ```bash # Fails — personal project + team agent = context mismatch curl -X POST "https://api.wiro.ai/v1/UserAgent/Message/Send" \ -H "x-api-key: YOUR_PERSONAL_API_KEY" \ -d '{"useragentguid": "team-agent-guid-here", "message": "Hello"}' # Returns: "This agent belongs to a team. Switch to the team context to access it." ``` ### Wallet Billing Flow When a task runs in team context: 1. The project's `teamguid` is resolved from the API key 2. The task is created with `teamguid` set 3. On completion, the billing UUID is set to `teamguid` (not the user's UUID) 4. The wallet transaction is recorded against the team wallet 5. The cost is deducted from the team wallet balance ``` API Key → Project (teamguid) → Task (teamguid) → Wallet Transaction (uuid=teamguid) ``` For personal context, the flow is the same but `teamguid` is `null` and billing uses the user's personal UUID. ## Best Practices - **Separate projects by environment** — create distinct team projects for development, staging, and production. The team context is resolved automatically from the API key. - **Check agent context before messaging** — if you build a multi-tenant application, ensure the project and agent belong to the same workspace - **Transfer resources carefully** — agents can only access projects in the same workspace. Plan your resource layout before transferring ## What's Next - [Organizations & Teams Overview](/docs/organizations-overview) — Concepts and workspace hierarchy - [Managing Teams](/docs/organizations-managing-teams) — Create organizations, invite members, manage roles - [Team Billing & Spending](/docs/organizations-billing) — Wallets, spend limits, and model access controls - [Authentication](/docs/authentication) — API key setup and authentication methods - [Projects](/docs/projects) — Project management and API credentials