# Create invoice

POST https://agents.gwop.io/v1/invoices
Content-Type: application/json

Create an invoice for agent payment.

The response contains two IDs:
- `id` is the merchant-side UUID
- `public_invoice_id` is the payer-facing `inv_*` identifier


Reference: https://docs.gwop.io/api-reference/gwop-api/invoices/create-invoice

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Gwop API
  version: 1.0.0
paths:
  /v1/invoices:
    post:
      operationId: create-invoice
      summary: Create invoice
      description: |
        Create an invoice for agent payment.

        The response contains two IDs:
        - `id` is the merchant-side UUID
        - `public_invoice_id` is the payer-facing `inv_*` identifier
      tags:
        - subpackage_invoices
      parameters:
        - name: Authorization
          in: header
          description: |
            Merchant API key (`sk_m_*`).

            ```
            Authorization: Bearer sk_m_abc123def456...
            ```
          required: true
          schema:
            type: string
        - name: Idempotency-Key
          in: header
          description: |
            Client-generated UUID v4 for safe retries.
            Requests with the same key return the original response.
          required: false
          schema:
            type: string
            format: uuid
      responses:
        '201':
          description: Invoice created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateInvoiceResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid authentication
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Valid authentication but insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInvoiceRequest'
servers:
  - url: https://agents.gwop.io
components:
  schemas:
    MoneyUsdc:
      type: integer
      format: int64
      description: >-
        USDC amount in atomic units (6 decimals). Used in REST response bodies.
        1000000 = 1.00 USDC.
      title: MoneyUsdc
    CreateInvoiceRequest:
      type: object
      properties:
        amount_usdc:
          $ref: '#/components/schemas/MoneyUsdc'
        description:
          type: string
        metadata:
          type: object
          additionalProperties:
            description: Any type
        metadata_public:
          type: boolean
          default: false
        expires_in_seconds:
          type: integer
          default: 900
      required:
        - amount_usdc
      title: CreateInvoiceRequest
    UUID:
      type: string
      format: uuid
      title: UUID
    PublicInvoiceId:
      type: string
      title: PublicInvoiceId
    Currency:
      type: string
      enum:
        - USDC
      title: Currency
    InvoiceStatus:
      type: string
      enum:
        - OPEN
        - PAYING
        - PAID
        - EXPIRED
        - CANCELED
      title: InvoiceStatus
    Timestamp:
      type: string
      format: date-time
      title: Timestamp
    AgentProtocolVersion:
      type: string
      enum:
        - '1.0'
      title: AgentProtocolVersion
    AgentProtocolFlow:
      type: string
      enum:
        - invoice_checkout
        - invoice_gwop_wallet
        - invoice_x402
      title: AgentProtocolFlow
    AgentProtocolState:
      type: string
      enum:
        - invoice_created
        - invoice_open
        - invoice_paying
        - invoice_paid
        - invoice_unavailable
        - payment_required
      title: AgentProtocolState
    AgentProtocolNextActionMethod:
      type: string
      enum:
        - GET
        - POST
      title: AgentProtocolNextActionMethod
    AgentProtocolNextActionRetryStrategy:
      type: string
      enum:
        - none
        - fixed_interval
      title: AgentProtocolNextActionRetryStrategy
    AgentProtocolNextActionRetry:
      type: object
      properties:
        strategy:
          $ref: '#/components/schemas/AgentProtocolNextActionRetryStrategy'
        retry_after_seconds:
          type: integer
        max_attempts:
          type: integer
      title: AgentProtocolNextActionRetry
    AgentProtocolNextAction:
      type: object
      properties:
        method:
          $ref: '#/components/schemas/AgentProtocolNextActionMethod'
        path:
          type: string
        body_template:
          type: object
          additionalProperties:
            description: Any type
        expect_status:
          type: array
          items:
            type: integer
        retry:
          $ref: '#/components/schemas/AgentProtocolNextActionRetry'
      title: AgentProtocolNextAction
    AgentProtocolCompletionCheckMethod:
      type: string
      enum:
        - GET
      title: AgentProtocolCompletionCheckMethod
    AgentProtocolCompletionCheckField:
      type: string
      enum:
        - status
      title: AgentProtocolCompletionCheckField
    AgentProtocolCompletionCheckSuccessValue:
      type: string
      enum:
        - PAID
      title: AgentProtocolCompletionCheckSuccessValue
    AgentProtocolCompletionCheck:
      type: object
      properties:
        method:
          $ref: '#/components/schemas/AgentProtocolCompletionCheckMethod'
        path:
          type: string
        field:
          $ref: '#/components/schemas/AgentProtocolCompletionCheckField'
        success_value:
          $ref: '#/components/schemas/AgentProtocolCompletionCheckSuccessValue'
      required:
        - method
        - path
        - field
        - success_value
      title: AgentProtocolCompletionCheck
    AgentProtocolReceiptPolicyMode:
      type: string
      enum:
        - hard_optional
      title: AgentProtocolReceiptPolicyMode
    AgentProtocolReceiptPolicy:
      type: object
      properties:
        mode:
          $ref: '#/components/schemas/AgentProtocolReceiptPolicyMode'
        optional_receipt_email:
          type: boolean
        prompt_when_available:
          type: boolean
        do_not_block_on_absent:
          type: boolean
      title: AgentProtocolReceiptPolicy
    AgentProtocol:
      type: object
      properties:
        version:
          $ref: '#/components/schemas/AgentProtocolVersion'
        flow:
          $ref: '#/components/schemas/AgentProtocolFlow'
        state:
          $ref: '#/components/schemas/AgentProtocolState'
        goal:
          type: string
        steps:
          type: array
          items:
            type: string
        next_action:
          $ref: '#/components/schemas/AgentProtocolNextAction'
        completion_check:
          $ref: '#/components/schemas/AgentProtocolCompletionCheck'
        receipt_policy:
          $ref: '#/components/schemas/AgentProtocolReceiptPolicy'
      required:
        - version
        - flow
        - state
        - goal
        - steps
        - completion_check
      title: AgentProtocol
    CreateInvoiceResponse:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/UUID'
        public_invoice_id:
          $ref: '#/components/schemas/PublicInvoiceId'
        merchant_id:
          $ref: '#/components/schemas/UUID'
        amount_usdc:
          $ref: '#/components/schemas/MoneyUsdc'
        currency:
          $ref: '#/components/schemas/Currency'
        status:
          $ref: '#/components/schemas/InvoiceStatus'
        description:
          type: string
        metadata:
          type: object
          additionalProperties:
            description: Any type
        metadata_public:
          type: boolean
        created_at:
          $ref: '#/components/schemas/Timestamp'
        expires_at:
          $ref: '#/components/schemas/Timestamp'
        agent_protocol:
          $ref: '#/components/schemas/AgentProtocol'
      required:
        - id
        - public_invoice_id
        - merchant_id
        - amount_usdc
        - currency
        - status
        - metadata_public
        - created_at
        - expires_at
        - agent_protocol
      title: CreateInvoiceResponse
    ErrorResponseError:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        details:
          type: object
          additionalProperties:
            description: Any type
        requestId:
          type: string
      required:
        - code
        - message
      title: ErrorResponseError
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorResponseError'
      required:
        - error
      title: ErrorResponse
    RateLimitError:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorResponseError'
      required:
        - error
      title: RateLimitError
  securitySchemes:
    MerchantApiKey:
      type: http
      scheme: bearer
      description: |
        Merchant API key (`sk_m_*`).

        ```
        Authorization: Bearer sk_m_abc123def456...
        ```

```

## SDK Code Examples

```python minimal
import requests

url = "https://agents.gwop.io/v1/invoices"

payload = { "amount_usdc": 1000000 }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript minimal
const url = 'https://agents.gwop.io/v1/invoices';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"amount_usdc":1000000}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go minimal
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://agents.gwop.io/v1/invoices"

	payload := strings.NewReader("{\n  \"amount_usdc\": 1000000\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby minimal
require 'uri'
require 'net/http'

url = URI("https://agents.gwop.io/v1/invoices")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount_usdc\": 1000000\n}"

response = http.request(request)
puts response.read_body
```

```java minimal
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://agents.gwop.io/v1/invoices")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount_usdc\": 1000000\n}")
  .asString();
```

```php minimal
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://agents.gwop.io/v1/invoices', [
  'body' => '{
  "amount_usdc": 1000000
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp minimal
using RestSharp;

var client = new RestClient("https://agents.gwop.io/v1/invoices");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount_usdc\": 1000000\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift minimal
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["amount_usdc": 1000000] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://agents.gwop.io/v1/invoices")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

```python
import requests

url = "https://agents.gwop.io/v1/invoices"

payload = {
    "amount_usdc": 5000000,
    "description": "Starter plan — 300 credits",
    "metadata": { "plan_id": "starter" },
    "metadata_public": False
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://agents.gwop.io/v1/invoices';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"amount_usdc":5000000,"description":"Starter plan — 300 credits","metadata":{"plan_id":"starter"},"metadata_public":false}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://agents.gwop.io/v1/invoices"

	payload := strings.NewReader("{\n  \"amount_usdc\": 5000000,\n  \"description\": \"Starter plan — 300 credits\",\n  \"metadata\": {\n    \"plan_id\": \"starter\"\n  },\n  \"metadata_public\": false\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://agents.gwop.io/v1/invoices")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount_usdc\": 5000000,\n  \"description\": \"Starter plan — 300 credits\",\n  \"metadata\": {\n    \"plan_id\": \"starter\"\n  },\n  \"metadata_public\": false\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://agents.gwop.io/v1/invoices")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount_usdc\": 5000000,\n  \"description\": \"Starter plan — 300 credits\",\n  \"metadata\": {\n    \"plan_id\": \"starter\"\n  },\n  \"metadata_public\": false\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://agents.gwop.io/v1/invoices', [
  'body' => '{
  "amount_usdc": 5000000,
  "description": "Starter plan — 300 credits",
  "metadata": {
    "plan_id": "starter"
  },
  "metadata_public": false
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://agents.gwop.io/v1/invoices");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount_usdc\": 5000000,\n  \"description\": \"Starter plan — 300 credits\",\n  \"metadata\": {\n    \"plan_id\": \"starter\"\n  },\n  \"metadata_public\": false\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "amount_usdc": 5000000,
  "description": "Starter plan — 300 credits",
  "metadata": ["plan_id": "starter"],
  "metadata_public": false
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://agents.gwop.io/v1/invoices")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```