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

# API reference

> Call models through the Weflayr gateway, and read or write your Weflayr data.

Weflayr has two APIs, authenticated by the same project API keys:

| API | Base URL | What it does |
| - | - | - |
| [Gateway](/api/gateway/responses) | `https://gateway.weflayr.com/v1` | Calls any model of any provider in the OpenAI format, or a [routing strategy](/product/routing-strategies). |
| [Management](/api/management/get-costs) | `https://app.weflayr.com/api` | Reads your costs, margin and project data, and writes revenue, key metrics and customer tags. Also served as an [MCP server](/api/management/mcp-server). |

## Authentication

Create a key in [API keys](/product/api-keys), and send it as a Bearer token on every request:

```bash theme={null}
Authorization: Bearer <WEFLAYR_API_KEY>
```

A key belongs to one project and carries one or both scopes:

* **Gateway**: calls models through the gateway. Each call is paid from your organization's [credits](/product/credits).
* **Management**: everything else (the management API and the MCP server).

## Project types

Some management routes only apply to one [project type](/product/organizations-and-projects#internal-projects):

| Project type | For | Routes |
| - | - | - |
| **Revenue-linked cost** (default) | A product your customers pay for | [Get margin](/api/management/get-margin), and the revenue routes ([Set](/api/management/set-revenue), [Get](/api/management/get-revenue), [Delete](/api/management/delete-revenue)) |
| **Internal cost** | An internal tool with no revenue, tracked per user | [Get performance](/api/management/get-performance), and the key metrics routes ([Set](/api/management/set-key-metrics), [Get](/api/management/get-key-metrics), [Delete](/api/management/delete-key-metrics)) |

Get margin answers a `400` on an internal project, and Get performance on a revenue-linked one.

## Errors

The management API answers an error with its HTTP status and `{"error": "<message>"}`: `401` for a missing or invalid key, `422` for an invalid payload (with a `detail` list naming each field), `400` for a route that does not apply to the project's type.

The gateway answers in OpenAI's error format, so OpenAI clients handle it as they would OpenAI's:

```json theme={null}
{
  "error": {
    "type": "invalid_request_error",
    "code": "unknown_model",
    "message": "...",
    "param": null
  }
}
```

| Status | `code` | When |
| - | - | - |
| 400 | `unknown_model`, `model_not_served_by_provider`, `model_not_available_in_region`, `service_tier_not_offered`, `mapping_error`, `unknown_routing_strategy`, `invalid_routing_strategy_version`, `routing_strategy_archived`, `field_not_allowed_with_routing_strategy` | The request names a model, provider, region or routing strategy that cannot serve it, or a field that model does not take. |
| 401 | `invalid_credentials` | The key is missing, unknown or expired. |
| 402 | `insufficient_credits` | Your organization has no credits left. [Top up](/product/credits) to keep calling models. |
| 403 | `gateway_scope_required` | The key does not have the Gateway scope. |
| 422 | `invalid_json` | The body is not a valid request. |
| 429 | `rate_limited` | Too many requests: retry after the `Retry-After` header's delay. A provider's own 429 is passed on as `provider_error`. |
| 500 | `routing_deployments_failed` | Every model of the routing strategy failed. The message lists each attempt. |
| 502 | `provider_error` | The provider failed to answer. |

When the provider refuses a request, the error also lists in `weflayr_warnings` the parameters the model does not take, as the likely cause.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.