DoublewordDoubleword

Creating an API Key

API keys provide programmatic access to the Doubleword Inference API. You need one to make requests from your code, the DW CLI, or any of the integration packages. Keys can also carry a spending cap and be managed across an organization, covered in the sections below.

The Doubleword API is fully OpenAI-compatible at https://api.doubleword.ai/v1. Any SDK or tool that supports a custom OpenAI endpoint, including the official OpenAI Python and Node.js libraries, can use your API key to list models, create chat completions, generate embeddings, and submit batches. The API is also Anthropic-compatible through the Messages API, so tools built on the Anthropic SDK can use the same key. See Anthropic API compatibility for the base URL and setup.

How to Create an API Key

  1. Open the API Keys page in the Doubleword Console
  2. Click Create API Key
  3. Give it a name (e.g. "development", "production", "research")
  4. Copy the key immediately, since it won't be shown again
  5. (Optional) Add a spending cap so the key can only spend up to a set amount, covered in Spending caps and scoped keys below

You can also create a key directly from a model card:

  1. Select the model you want to use
  2. Click the API button
  3. When the code example loads, select Fill API Key to generate a new key

Using Your API Key

Set it as an environment variable (recommended for production):

export DOUBLEWORD_API_KEY="{{apiKey}}"

Or pass it directly in code:

from autobatcher import BatchOpenAI
import asyncio

client = BatchOpenAI(
    base_url="https://api.doubleword.ai/v1",
    api_key="{{apiKey}}",
)

async def main():
    response = await client.chat.completions.create(
        model="{{selectedModel.id}}",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)
    await client.close()

asyncio.run(main())

Autobatcher is a drop-in AsyncOpenAI replacement that transparently batches requests for up to 90% cost savings. You can also use the standard openai Python or Node.js libraries directly if you prefer real-time responses.

Best Practices

  • Create separate keys for different applications or environments (dev, staging, production) so you can revoke one without affecting others
  • Never commit keys to version control. Use environment variables or a secrets manager
  • Rotate keys in place from the console using the rotate button rather than deleting and recreating them. Rotating gives the key a new secret while keeping the same key, so a key named "production" stays "production" and its usage and attribution carry over. Rotate a key if you think it is compromised, or periodically as good practice. The new secret is only shown once, like the original
  • Organization keys. If you're part of an organization, switch to the org context before creating a key so usage is billed to the organization. See Organization key management below for assigning capped keys to members

Spending caps and scoped keys

A key can carry a spending cap, so you can hand one to an autonomous agent, a data pipeline, or a single job and know exactly how much it is allowed to spend. Scoping one key per use case, such as agents, pipeline, testing, and production, also gives you clean per-task usage tracking and lets you revoke one key without touching the others.

Set a cap when you create the key:

  1. On the API Keys page, click Create API Key
  2. Set an Amount in dollars, then pick a Frequency. See below for more details on the available settings and limits, including 'one-off' which gives a key a fixed spending limit. Fixed limits do not automatically reset when the credits allocated have been exhausted. You can still manually reset the key for a new 'one-off' spend. This means it can continue to be used, without revoking it.
  3. Copy the key immediately, as with any key

The default is no limit ('N/A'). To cap the key, set an amount and choose how often it resets with the Frequency option:

  • 1-off is a fixed limit. The key spends up to the amount once and then stops, with no reset.
  • Daily, Weekly, or Monthly refreshes the key back to the full amount at the start of each day, week, or month.

If you manage a key, you can reset its limit at any time. If an agent spends its whole budget mid-week, reset it to let the key keep working. Editing the amount or the frequency also resets the current period.

Organization key management

If you manage a team, the organization context in the console lets you decide who can create keys, assign keys that carry their own caps, and keep spend attributable to each member.

  • Roles and permissions. When you add a member, you decide whether they can manage and create their own keys. A member who can create their own keys can create them without a cap, so if you want to control what a member spends, set them so they cannot manage their own keys and can only use the capped keys an admin assigns them. You can change this for a member at any time
  • Assigning keys. In an org context, creating a key starts with choosing who it is for, using the Assign to User field, and you can give it an optional spending cap. Give each member, or each of their use cases, a separate key so usage stays attributable and any one key can be revoked on its own
  • Revealing an assigned key. When you assign a key to a member, its button reads Reveal key. The first time the member opens it, the secret is shown once so they can copy it, and the button then changes to Rotate key. Rotating issues a new secret, again shown only once, and retires the old one. An admin can rotate a member's key at any time, for example if it may be compromised or to cut off that member's access to the organization's credits
  • Batch submissions. Every batch sent to the API directly needs a key, for every user. In the console UI it depends on the member's permissions. A member whose keys are all managed by an admin must pick one of their assigned keys to bill each batch to. A member who can manage their own keys, and any admin, can bill a batch to the organization's credits, or pick a specific key. If the key a batch is billed to has a cap, that cap applies to the batch, the same as any other request
  • Offboarding and demotion. Revoking a member's key-generation rights does not delete the keys they already hold. When you demote or offboard someone, audit their keys and delete or rotate any you no longer want in use, otherwise an old key could keep spending outside your intended limits